Docker容器下安装Kong网关
建议看这篇博客:https://www.cnblogs.com/dalianpai/p/13675102.html
1 官网说明:
这是一个简单的示例,显示了如何将Kong容器连接到Cassandra或PostgreSQL容器。
-
创建一个Docker网络
您将需要创建一个自定义网络,以使容器能够发现彼此并进行通信。在此示例中
kong-net
为网络名称,您可以使用任何名称。$ docker network create kong-net
-
启动你的数据库
如果您想使用Cassandra容器:
$ docker run -d --name kong-database \ --network=kong-net \ -p 9042:9042 \ cassandra:3
如果您想使用PostgreSQL容器:
$ 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
-
准备数据库
使用临时Kong容器运行迁移:
$ docker run --rm \ --network=kong-net \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -e "KONG_PG_PASSWORD=kong" \ -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ kong:latest kong migrations bootstrap
在上面的示例中,同时配置了Cassandra和PostgreSQL,但是您应该
KONG_DATABASE
使用cassandra
或更新环境变量postgres
。Kong <0.15的注意事项:Kong版本低于0.15(最大0.14)时,请使用
up
子命令代替bootstrap
。还要注意,Kong <0.15时,永远不要同时运行迁移。一次只能有一个Kong节点执行迁移。对于0.15、1.0及更高版本,此限制被取消。 -
刚开始
运行迁移并准备好数据库后,启动将连接到数据库容器的Kong容器,就像临时迁移容器一样:
$ docker run -d --name kong \ --network=kong-net \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -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 127.0.0.1:8001:8001 \ -p 127.0.0.1:8444:8444 \ kong:latest
-
使用kong
Kong正在运行:
$ curl -i http://localhost:8001/
安装如下
[root@iZ1la3d1xbmukrZ ~]# 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 f301c795501a351b3159236a629cec57c05eb5adc1a1351b9708b29ead505c72 [root@iZ1la3d1xbmukrZ ~]# docker run --rm \ > --network=kong-net \ > -e "KONG_DATABASE=postgres" \ > -e "KONG_PG_HOST=kong-database" \ > -e "KONG_PG_PASSWORD=kong" \ > -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ > kong:latest kong migrations bootstrap Bootstrapping database... migrating core on database 'kong'... core migrated up to: 000_base (executed) core migrated up to: 003_100_to_110 (executed) core migrated up to: 004_110_to_120 (executed) core migrated up to: 005_120_to_130 (executed) core migrated up to: 006_130_to_140 (executed) core migrated up to: 007_140_to_150 (executed) core migrated up to: 008_150_to_200 (executed) migrating hmac-auth on database 'kong'... hmac-auth migrated up to: 000_base_hmac_auth (executed) hmac-auth migrated up to: 002_130_to_140 (executed) migrating oauth2 on database 'kong'... oauth2 migrated up to: 000_base_oauth2 (executed) oauth2 migrated up to: 003_130_to_140 (executed) migrating jwt on database 'kong'... jwt migrated up to: 000_base_jwt (executed) jwt migrated up to: 002_130_to_140 (executed) migrating basic-auth on database 'kong'... basic-auth migrated up to: 000_base_basic_auth (executed) basic-auth migrated up to: 002_130_to_140 (executed) migrating key-auth on database 'kong'... key-auth migrated up to: 000_base_key_auth (executed) key-auth migrated up to: 002_130_to_140 (executed) migrating rate-limiting on database 'kong'... rate-limiting migrated up to: 000_base_rate_limiting (executed) rate-limiting migrated up to: 003_10_to_112 (executed) migrating acl on database 'kong'... acl migrated up to: 000_base_acl (executed) acl migrated up to: 002_130_to_140 (executed) migrating acme on database 'kong'... acme migrated up to: 000_base_acme (executed) migrating response-ratelimiting on database 'kong'... response-ratelimiting migrated up to: 000_base_response_rate_limiting (executed) migrating session on database 'kong'... session migrated up to: 000_base_session (executed) 24 migrations processed 24 executed Database is up-to-date [root@iZ1la3d1xbmukrZ ~]# docker run -d --name kong \ > --network=kong-net \ > -e "KONG_DATABASE=postgres" \ > -e "KONG_PG_HOST=kong-database" \ > -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 127.0.0.1:8001:8001 \ > -p 127.0.0.1:8444:8444 \ > kong:latest e5ca4768b2801e7ef182dea51124db2eae1f98ee49cd4d558282592c2fe79f56 [root@iZ1la3d1xbmukrZ ~]# curl -i http://localhost:8001/ HTTP/1.1 200 OK Date: Sat, 18 Apr 2020 13:31:18 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Access-Control-Allow-Origin: * Server: kong/2.0.3 Content-Length: 8688 X-Kong-Admin-Latency: 161 {"plugins":{"enabled_in_cluster":[],"available_on_server":{"correlation-id":true,"pre-function":true,"cors":true,"ldap-auth":true,"loggly":true,"hmac-auth":true,"zipkin":true,"request-size-limiting":true,"azure-functions":true,"request-transformer":true,"oauth2":true,"response-transformer":true,"ip-restriction":true,"statsd":true,"jwt":true,"proxy-cache":true,"basic-auth":true,"key-auth":true,"http-log":true,"datadog":true,"tcp-log":true,"rate-limiting":true,"post-function":true,"prometheus":true
2.0 安装监控 Konga
docker pull pantsel/konga:latest
- 方案1 konga
docker run --rm pantsel/konga:latest -c prepare -a postgres -u postgresql://kong:@172.18.0.1:5432/konga docker run -p 1337:1337 \ --network kong-net \ --name konga \ -e "NODE_ENV=production" \ -e "DB_ADAPTER=postgres" \ -e "DB_URI=postgresql://kong:@172.18.0.1:5432/konga" \ pantsel/konga
压缩版:
docker run -p 1337:1337 --network kong-net --name konga -e "NODE_ENV=production" -e "DB_ADAPTER=postgres" -e "DB_URI=postgresql://kong:@172.18.0.1:5432/konga" pantsel/konga
- 方案2 kong-dashboard
docker run --rm -p 8080:8080 --network=kong-net pgbi/kong-dashboard start --kong-url http://kong:8001
http://{konga-ip}:1337/