kong

5 mins start kong

start DB and kong

docker network create kong-net

docker run -d --name kong-database --network=kong-net -p 5432:5432 -e "POSTGRES_USER=kong" -e "POSTGRES_DB=kong" postgres:9.5

docker run --rm --network=kong-net -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database" -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" kong:latest kong migrations up

docker run -d --name kong --network=kong-net  --link kong-database:kong-database -e "KONG_DATABASE=postgres"  -e "KONG_PG_HOST=kong-database"  -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout"  -e "KONG_PROXY_ERROR_LOG=/dev/stderr"  -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" -p 8000:8000 -p 8443:8443  -p 8001:8001  -p 8444:8444 kong:latest

add api and retrive

add api

curl -i -X POST --url http://localhost:8001/apis/ --data 'name=example-api' --data 'hosts=example.com' --data 'upstream_url=http://httpbin.org'

test api

curl -i -X GET --url http://localhost:8000/ --header 'Host: example.com'

list apis

curl -i -X GET --url http://localhost:8001/apis

ldap

啟動 ldap plugin:

curl -i -X POST   --url http://localhost:8001/apis/example-api/plugins/ --data 'name=ldap-auth'  --data "config.hide_credentials=true"     --data "config.ldap_host=XXX.nchc.org.tw" --data "config.ldap_port=389" --data "config.base_dn=ou=SXT9538,ou=ai-test,ou=iam,ou=nchc,ou=org,ou=tw" --data "config.attribute=cn" --data "config.cache_ttl=60"
curl -i  -H "Host: ipgod.nchc.org.tw" -H 'Authorization: ldap XXXXXXkV3THFXeDZwWXY4bkhQRzM='  http://127.0.0.1:8000/api/3/action/package_list

密碼產生方式:

echo -n 'test01:XXXXXXXYv8nHPG3' | base64 => xxxxxxxkV3THFXeDZwWXY4bkhQRzM=

maintain database

backup

docker run -i -t  --network=kong-net -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database" -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" ubuntu /bin/bash

back up in maintainer host

apt-get update
apt-get install postgresql-client-common postgresql-client
whereis pg_dump
whereis pg_dumpall

check kong env

root@65502a3391db:/home/tmp# env  | grep KONG_PG_HOST
KONG_PG_HOST=kong-database

start back up DB:

pg_dump -h  kong-database -U kong  kong > kong.dump
pg_dumpall -h  kong-database -U kong > pgalldb2.dump

crash

docker stop ....
docker rm ....

retore kong and db

start postgreSQL

docker run -d --name kong-database --network=kong-net -p 5432:5432 -e "POSTGRES_USER=kong" -e "POSTGRES_DB=kong" postgres:9.5

back to maintainer's host and run psql command

psql -h kong-database -U kong  -f pgalldb2.dump

resume kong

docker run -d --name kong --network=kong-net  --link kong-database:kong-database -e "KONG_DATABASE=postgres"  -e "KONG_PG_HOST=kong-database"  -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout"  -e "KONG_PROXY_ERROR_LOG=/dev/stderr"  -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" -p 8000:8000 -p 8443:8443  -p 8001:8001  -p 8444:8444 kong:latest

reference from kong official document.

[*] https://docs.konghq.com/install/docker/

Comments