本文只讲述如何使用docker部署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" \
-e "POSTGRES_PASSWORD=kong" \
postgres:9.6
network 要与docker虚拟网络一致
docker run --rm \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kong" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
kong:latest kong migrations bootstrap
docker run -d --name kong \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kong" \
-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" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong:latest
我目前只需要关心Route-Service-Upstream-Target即可
curl -X POST http://konghost:8001/upstreams --data "name=demoupstream"
konghost:kong部署的地址
demoupstream:你自己的负载名
示例:curl -X POST http://localhost:8001/upstreams --data "name=test"
curl -X POST http://konghost:8001/upstreams/demoupstream/targets --data "target=localhost:3000" --data "weight=100"
curl -X POST http://konghost:8001/services --data "name=demo" --data "host=demoupstream" --data "url=http://demo.com/"
curl -X POST http://konghost:8001/services/demo/routes --data "paths[]=/demo" --data "hosts[]=demo.com"
curl -i http://konghost:8000/demo --header host:demo.com
其中,8000与8001为HTTP端口,8443与8444为HTTPS端口。
8001:api 端口用于配置和获取 Route-Service-Upstream-Target
8000:kong代理端口地址,配置好Route-Service-Upstream-Target后,使用该端口访问kong,然后kong转发实际服务器