【发布时间】:2021-04-13 06:16:58
【问题描述】:
我正在使用 Kong 和 docker,当我在没有“DNS_RESOLVER”的情况下启动时,它工作正常,这是命令
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_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:1.4.3-alpine
我想在consul上使用Kong,我发现我应该在命令中添加-e "KONG_DNS_RESOLVER=10.114.205.170:8600"。所以最终的命令是
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_DNS_RESOLVER=10.114.205.170:8600" /
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" /
-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:1.4.3-alpine
10.114.205.170:8600 是领事的 DNS SERVER。
但是Kong启动错误,错误日志是
2021/04/13 03:10:17 [crit] 41#0: *8 [lua] balancer.lua:540: could not obtain list of upstreams: [postgres] [cosocket] DNS resolution failed: dns server error: 2 server failure. Tried: ["(short)kong-database:(na) - cache-miss","kong-database:33 - cache-miss/scheduled/querying/dns server error: 2 server failure","kong-database:1 - cache-miss/scheduled/querying/dns server error: 2 server failure","kong-database:5 - cache-miss/scheduled/querying/dns server error: 2 server failure"], context: ngx.timer
...
2021/04/13 03:10:26 [error] 34#0: *253 [kong] kong.lua:42 [postgres] [cosocket] DNS resolution failed: dns server error: 2 server failure. Tried: ["(short)kong-database:(na) - cache-miss","kong-database:33 - cache-miss/scheduled/querying/dns server error: 2 server failure","kong-database:1 - cache-miss/scheduled/querying/dns server error: 2 server failure","kong-database:5 - cache-miss/scheduled/querying/dns server error: 2 server failure"], client: 172.18.0.1, server: kong_admin, request: "GET / HTTP/1.1", host: "127.0.0.1:8001"
...
2021/04/13 03:11:16 [error] 34#0: *1594 [lua] connector.lua:356: unable to clean expired rows from PostgreSQL database ([cosocket] DNS resolution failed: dns server error: 2 server failure. Tried: ["(short)kong-database:(na) - cache-miss","kong-database:33 - cache-miss/scheduled/querying/dns server error: 2 server failure","kong-database:1 - cache-miss/scheduled/querying/dns server error: 2 server failure","kong-database:5 - cache-miss/scheduled/querying/dns server error: 2 server failure"]), context: ngx.timer
我确信领事服务器工作正常。我对运行 Kong 的主机进行了 consul 查询并得到了正确的响应
root@virtual-machine:/# dig @10.114.205.170 -p 8600 RdTestServiceProxy.service.consul
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @10.114.205.170 -p 8600 RdTestServiceProxy.service.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8122
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;RdTestServiceProxy.service.consul. IN A
;; ANSWER SECTION:
RdTestServiceProxy.service.consul. 0 IN A 10.114.205.151
;; Query time: 1 msec
;; SERVER: 10.114.205.170#8600(10.114.205.170)
;; WHEN: Tue Apr 13 13:54:45 CST 2021
;; MSG SIZE rcvd: 78
那么 Kong 出了什么问题,如何使用 dns_resolver 启动 Kong?
【问题讨论】:
-
consul 版本:1.7.1 Kong 版本:1.4.3-alpine