Kong 在教程中找不到样品瓶容器

Kong cannot find sample flask container in tutorial

我开始关注 this docker/KONG installation tutorial 他们创建了一个名为 "kong-net" 的网络并启动了 KONG 和 postgresql 容器。

然后我跳到this docker/kong tutorial the registers a sample flask container as an API in KONG.

在使用 flask 服务和相关路由配置 KONG 容器时,我没有看到任何令人担忧的事情。

样品瓶容器似乎工作正常:

curl http://localhost:5055/api/v1/test1
curl http://localhost:5055/api/v1/test2

我得到了预期的结果:

{"message":"first end point test1 is called","status_code":200}

这些命令的结果看起来不错: curl -i -X POST --url http://localhost:8001/services/ --data 'name=testApi' --data 'url=http://localhost:5055' curl http://localhost:8001/routes | json_pp

一切都很好,直到我得到这个命令来测试 KONG:

curl -i -X GET --url http://localhost:8000/api/v1/test1 --header 'Host: localhost'

我认为 KONG 应该将其转发给样品瓶容器。

相反,我看到了这个错误:

HTTP/1.1 502 Bad Gateway
Date: Wed, 08 May 2019 18:20:00 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: kong/1.1.2
X-Kong-Upstream-Latency: 1
X-Kong-Proxy-Latency: 35
Via: kong/1.1.2

An invalid response was received from the upstream server

在 KONG 容器的日志中,我看到了这个:

2019/05/08 16:56:57 [error] 38#0: *167134 connect() failed (111: 
Connection refused) while connecting to upstream, client: 
172.19.0.1, server: kong, request: "GET /api/v1/test1 HTTP/1.1", 
upstream: "http://127.0.0.1:5055/api/v1/test1", host: "localhost"
172.19.0.1 - - [08/May/2019:16:56:57 +0000] "GET /api/v1/test1 
HTTP/1.1" 502 69 "-" "curl/7.59.0"

KONG好像看不到localhost:5055.

我担心第一个教程让我创建的网络。

我尝试用这个命令停止、重建和重新运行烧瓶容器(所以烧瓶也是网络的一部分):

docker run -d --name flask  --network=kong-net -p 5055:5055  flask:test

唉,这并没有帮助。同样的错误!

当我输入时

docker network inspect kong-net

我现在看到烧瓶容器是 kong-net 的一部分。有这个必要吗?

我试过这个命令,它起作用了:

docker exec -ti kong sh -c "curl http://172.19.0.4:5055/api/v1/test1 "
{"message":"first end point test1 is called","status_code":200}

我正在使用 Windows10/cygwin-bash/docker18.09.2 进行所有操作,并打开 docker/kubernetes。

问题:

  1. 样品烧瓶应用程序是否需要 kong-net 的一部分?
  2. 教程似乎在说 kong 应该能够看到 127.0.0.1:5055。这个对吗?是不是教程错了?
  3. 如何让这个命令生效?

    curl -i -X GET --url http://localhost:8000/api/v1/test1 --header 'Host: localhost'

您需要注册路线:

curl -i -X POST \
 --url http://localhost:8001/services/testApi/routes \
 --data 'hosts[]=localhost' \
 --data 'paths[]=/api/v1/test1' \
 --data 'strip_path=false' \
 --data 'methods[]=GET'

当 Kong 作为 docker 容器安装时 'localhost' 表示 Kong 容器的环回地址 - 而不是主机。在 Kong 中注册的端点应该可以从 Kong 容器中解析。

因此,您可以更改注册以使用 Kong 容器可访问的后端服务的实际 IP 和端口,因此,如果您的后端也是一个 docker 容器并且其端口 5055 映射到端口15055在主机上,然后在Kong中注册应该使用主机IP和端口15055.