我们已经完成了kong的基本设置(API创建和订阅(,接下来通过以下步骤进行kong网关设置:
-
Kong网关配置:创建声明性配置YAML文件,即kong.YAML
_format_version:";2.1〃;
services:
- name: my-service
url: https://<Hostname>/httpbin
plugins:
- name: oneapi
config:
api_version_shortname: kongdocumentation-v0
authentication:
authentication_type: apikey
routes:
- name: my-route
paths:
- /
- 通过调整占位符,开始使用'docker-run'命令运行kong网关
docker run --name kong -d
--env KONG_ONEAPI_ENVIRONMENT=<your_environment>
--env KONG_ONEAPI_GATEWAY_KEY=<your_gateway_key>
--env KONG_ONEAPI_GATEWAY_SECRET=<your_gateway_secret>
--env KONG_DATABASE=off
--env KONG_DECLARATIVE_CONFIG=/kong_dbless/kong.yaml
--env KONG_LOG_LEVEL=info
-v $PWD/kong.yaml:/kong_dbless/kong.yaml
-p 8000:8000 -p 8100:8100 kong:latest
- 当我通过使用对暴露状态端点的curl请求来检查网关是否已成功授权到API管理后端,而没有获得预期的输出时
通过检查创建的容器的日志,我们得到了一个错误响应。
错误:
2022/03/04 12:30:43 [error] 1098#0: *4 [kong] cache_manager.lua:156 [cache] failed to connect to Redis: [cosocket] DNS resolution failed: dns client error: 101 empty record received. Tried: ["(short):(na) - cache-miss",".apac.bg.corpintra.net:33 - cache-miss/scheduled/querying/try 1 error: bad name/scheduled/querying/try 2 error: bad name/dns lookup pool exceeded retries (1): bad name",":33 - cache-miss/scheduled/querying/dns client error: 101 empty record received",".apac.bg.corpintra.net:1 - cache-miss/scheduled/querying/try 1 error: bad name/scheduled/querying/try 2 error: bad name/dns lookup pool exceeded retries (1): bad name",":1 - cache-miss/scheduled/querying/dns client error: 101 empty record received",".apac.bg.corpintra.net:5 - cache-miss/scheduled/querying/try 1 error: bad name/scheduled/querying/try 2 error: bad name/dns lookup pool exceeded retries (1): bad name",":5 - cache-miss/scheduled/querying/dns client error: 101 empty record received"], context: ngx.timer
2022/03/04 12:30:43 [error] 1098#0: *4 [kong] cache_manager.lua:90 redis sanity check failed: failed to check gateway redis prefix: [cosocket] DNS resolution failed: dns client error: 101 empty record received. Tried: ["(short):(na) - cache-miss",".apac.bg.corpintra.net:33 - cache-miss/scheduled/querying/try 1 error: bad name/scheduled/querying/try 2 error: bad name/dns lookup pool exceeded retries (1): bad name",":33 - cache-miss/scheduled/querying/dns client error: 101 empty record received",".apac.bg.corpintra.net:1 - cache-miss/scheduled/querying/try 1 error: bad name/scheduled/querying/try 2 error: bad name/dns lookup pool exceeded retries (1): bad name",":1 - cache-miss/scheduled/querying/dns client error: 101 empty record received",".apac.bg.corpintra.net:5 - cache-miss/scheduled/querying/try 1 error: bad name/scheduled/querying/try 2 error: bad name/dns lookup pool exceeded retries (1): bad name",":5 - cache-miss/scheduled/querying/dns client error: 101 empty record received"], context: ngx.timer
有人能告诉我缺了什么吗,
如果您的服务运行在主机上,而不是在docker网络内(kong所在的位置(,那么您需要使用正确引用它
host.docker.internal
这里有一个视频,其中有一个你想要做的事情的例子:https://www.youtube.com/watch?v=DZZEKyH0MHQ