添加 API 到 Kong 失败
Adding API to Kong failed
我的docker-compose.yml
version: '2.1'
volumes:
kong_data: {}
networks:
kong-net:
services:
kong-migrations:
image: "${KONG_DOCKER_TAG:-kong:latest}"
command: kong migrations bootstrap
depends_on:
db:
condition: service_healthy
environment:
KONG_DATABASE: postgres
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: db
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
links:
- db:db
networks:
- kong-net
restart: on-failure
kong:
image: "${KONG_DOCKER_TAG:-kong:latest}"
user: "${KONG_USER:-root}"
depends_on:
db:
condition: service_healthy
environment:
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: '0.0.0.0:8001'
KONG_CASSANDRA_CONTACT_POINTS: db
KONG_DATABASE: postgres
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: db
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
networks:
- kong-net
ports:
- "8000:8000/tcp"
- "8001:8001/tcp"
- "8443:8443/tcp"
- "8444:8444/tcp"
restart: on-failure
db:
image: postgres:9.5
environment:
POSTGRES_DB: ${KONG_PG_DATABASE:-kong}
POSTGRES_PASSWORD: ${KONG_PG_PASSWORD:-kong}
POSTGRES_USER: ${KONG_PG_USER:-kong}
healthcheck:
test: ["CMD", "pg_isready", "-U", "${KONG_PG_USER:-kong}"]
interval: 30s
timeout: 30s
retries: 3
restart: on-failure
stdin_open: true
tty: true
networks:
- kong-net
volumes:
- kong_data:/var/lib/postgresql/data
go-server:
image: gobuild
networks:
- kong-net
restart: on-failure
我的 docker 个容器
docker ps --format '{{.Names}}'
chapter11_go-server_1
chapter11_kong_1
chapter11_db_1
我正在尝试向 Kong 管理员提出 POST 请求
API,它在端口 8001 上运行。但它失败了。
{
"name": "myapi",
"hosts": "server1",
"": "http://chapter11_go-server_1:3000",
"uris":["/api/v1"],
"strip_uri": true,
"preserve_host": false
}
输出
kong_1 | 172.21.0.1 - - [29/Apr/2019:10:36:58 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"
kong_1 | 172.21.0.1 - - [29/Apr/2019:10:47:30 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"
如何查明我的 POST 请求是否有问题?
什么是 upstream_url?
根据 Kong 1.0.0 changelog:
The API entity and related concepts such as the /apis endpoint, are removed (deprecated since 0.13.0, March 2018). Use Routes and Services instead.
自从 Kong 1.0 /apis
端点不再可用。因此,您得到了 404 Not found 响应。
要将 API 添加到 Kong,您必须使用 /services
和 /routes
。本教程介绍了如何操作:Configuring a Service
我的docker-compose.yml
version: '2.1'
volumes:
kong_data: {}
networks:
kong-net:
services:
kong-migrations:
image: "${KONG_DOCKER_TAG:-kong:latest}"
command: kong migrations bootstrap
depends_on:
db:
condition: service_healthy
environment:
KONG_DATABASE: postgres
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: db
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
links:
- db:db
networks:
- kong-net
restart: on-failure
kong:
image: "${KONG_DOCKER_TAG:-kong:latest}"
user: "${KONG_USER:-root}"
depends_on:
db:
condition: service_healthy
environment:
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: '0.0.0.0:8001'
KONG_CASSANDRA_CONTACT_POINTS: db
KONG_DATABASE: postgres
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: db
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong}
KONG_PG_USER: ${KONG_PG_USER:-kong}
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
networks:
- kong-net
ports:
- "8000:8000/tcp"
- "8001:8001/tcp"
- "8443:8443/tcp"
- "8444:8444/tcp"
restart: on-failure
db:
image: postgres:9.5
environment:
POSTGRES_DB: ${KONG_PG_DATABASE:-kong}
POSTGRES_PASSWORD: ${KONG_PG_PASSWORD:-kong}
POSTGRES_USER: ${KONG_PG_USER:-kong}
healthcheck:
test: ["CMD", "pg_isready", "-U", "${KONG_PG_USER:-kong}"]
interval: 30s
timeout: 30s
retries: 3
restart: on-failure
stdin_open: true
tty: true
networks:
- kong-net
volumes:
- kong_data:/var/lib/postgresql/data
go-server:
image: gobuild
networks:
- kong-net
restart: on-failure
我的 docker 个容器
docker ps --format '{{.Names}}'
chapter11_go-server_1
chapter11_kong_1
chapter11_db_1
我正在尝试向 Kong 管理员提出 POST 请求 API,它在端口 8001 上运行。但它失败了。
{
"name": "myapi",
"hosts": "server1",
"": "http://chapter11_go-server_1:3000",
"uris":["/api/v1"],
"strip_uri": true,
"preserve_host": false
}
输出
kong_1 | 172.21.0.1 - - [29/Apr/2019:10:36:58 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"
kong_1 | 172.21.0.1 - - [29/Apr/2019:10:47:30 +0000] "POST /apis HTTP/1.1" 404 23 "-" "PostmanRuntime/7.6.0"
如何查明我的 POST 请求是否有问题?
什么是 upstream_url?
根据 Kong 1.0.0 changelog:
The API entity and related concepts such as the /apis endpoint, are removed (deprecated since 0.13.0, March 2018). Use Routes and Services instead.
自从 Kong 1.0 /apis
端点不再可用。因此,您得到了 404 Not found 响应。
要将 API 添加到 Kong,您必须使用 /services
和 /routes
。本教程介绍了如何操作:Configuring a Service