首页 > 解决方案 > Kong 在教程中找不到示例烧瓶容器

问题描述

我开始遵循这个 docker/KONG 安装教程,他们在其中创建了一个名为“kong-net”的网络并启动了 KONG 和 postgresql 容器。

然后我跳到这个 docker/kong 教程,将一个示例烧瓶容器注册为 KONG 中的 API。.

在使用烧瓶服务和相关路由配置 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}

我在打开 docker/kubernetes 的情况下使用 Windows10/cygwin-bash/docker18.09.2 执行所有这些操作。

问题:

  1. 示例烧瓶应用程序是否需要成为 kong-net 的一部分?
  2. 该教程似乎在说 kong 应该能够看到 127.0.0.1:5055。它是否正确?教程错了吗?
  3. 我怎样才能使这个命令工作?

    curl -i -X GET --url http://localhost:8000/api/v1/test1 --header '主机:本地主机'

标签: dockerkong

解决方案


您需要注册路线:

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'

推荐阅读