官方部署文档:
https://docs.konghq.com/gateway/latest/install-and-run/docker/
一个不错的系列文章:
https://www.iocoder.cn/Kong/install/
Kong安装
本文部署剔除了企业版选项命令,密码请按照实际情况修改。
部署数据库
创建网络
docker network create kong-net
运行PostgreSQL容器
docker run -d --name kong-database \
--network=kong-net \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
-e "POSTGRES_PASSWORD=kongpass" \
postgres:9.6
初始化数据库
docker run --rm --network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_PASSWORD=kongpass" \
kong/kong-gateway:2.8.1.4-alpine kong migrations bootstrap
运行Kong网关
docker run -d --name kong-gateway \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kongpass" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
-p 8445:8445 \
-p 8003:8003 \
-p 8004:8004 \
kong/kong-gateway:2.8.1.4-alpine
测试
curl -i -X GET --url http://localhost:8001/services
HTTP/1.1 200 OK
Date: Mon, 29 Aug 2022 06:46:43 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
X-Kong-Admin-Request-ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Length: 23
X-Kong-Admin-Latency: 174
Server: kong/2.8.1.4-enterprise-edition
{"next":null,"data":[]}
Konga安装
docker run -d -p 1337:1337 \
--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 "DB_DATABASE=konga_db" \
-e "KONGA_HOOK_TIMEOUT=120000" \
--name konga \
pantsel/konga
使用docker-compose部署Kong/Konga
可能需要比较新的docker-compose
: https://github.com/docker/compose/releases/
version: '3.9'
x-kong-config: &kong-env
KONG_DATABASE: ${KONG_DATABASE:-postgres}
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
KONG_PG_HOST: db
KONG_PG_USER: ${KONG_PG_USER:-kong}
KONG_PG_PASSWORD: ${KONG_PG_PASSWORD:-kong@pass}
volumes:
kong_data: {}
kong_prefix_vol:
driver_opts:
type: tmpfs
device: tmpfs
kong_tmp_vol:
driver_opts:
type: tmpfs
device: tmpfs
networks:
kong-net:
external: false
services:
kong-migrations:
image: "${KONG_DOCKER_TAG:-kong:latest}"
command: kong migrations bootstrap
depends_on:
- db
environment:
<<: *kong-env
networks:
- kong-net
restart: on-failure
kong-migrations-up:
image: "${KONG_DOCKER_TAG:-kong:latest}"
command: kong migrations up && kong migrations finish
depends_on:
- db
environment:
<<: *kong-env
networks:
- kong-net
restart: on-failure
kong:
image: "${KONG_DOCKER_TAG:-kong:latest}"
user: "${KONG_USER:-kong}"
environment:
<<: *kong-env
KONG_PROXY_LISTEN: 0.0.0.0:8000, 0.0.0.0:8443 ssl
KONG_ADMIN_LISTEN: 0.0.0.0:8001, 0.0.0.0:8444 ssl
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
KONG_PREFIX: ${KONG_PREFIX:-/var/run/kong}
# KONG_DECLARATIVE_CONFIG: "/opt/kong/kong.yaml"
networks:
- kong-net
ports:
- "${KONG_INBOUND_PROXY_LISTEN:-0.0.0.0}:8000:8000/tcp"
- "${KONG_INBOUND_SSL_PROXY_LISTEN:-0.0.0.0}:8443:8443/tcp"
- "127.0.0.1:8001:8001/tcp"
- "127.0.0.1:8444:8444/tcp"
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 10s
retries: 10
restart: on-failure:5
read_only: true
volumes:
- kong_prefix_vol:${KONG_PREFIX:-/var/run/kong}
- kong_tmp_vol:/tmp
# - ./config:/opt/kong
security_opt:
- no-new-privileges
db:
image: postgres:9.5
environment:
POSTGRES_DB: ${KONG_PG_DATABASE:-kong}
POSTGRES_USER: ${KONG_PG_USER:-kong}
POSTGRES_PASSWORD: ${KONG_PG_PASSWORD:-kong@pass}
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
dns:
- 8.8.8.8
volumes:
- kong_data:/var/lib/postgresql/data
konga:
image: pantsel/konga
environment:
restart: always
networks:
- kong-net
environment:
DB_USER: ${KONG_PG_USER:-kong}
DB_HOST: db
DB_PASSWORD: ${KONG_PG_PASSWORD:-kong@pass}
DB_ADAPTER: postgres
DB_DATABASE: konga_db
NODE_ENV: ${NODE_ENV:-development}
depends_on:
- db
ports:
- "127.0.0.1:1337:1337"
konga初始化配置步骤可以参考:
https://blog.csdn.net/qq_20741133/article/details/118573978
本文配置的Konga监听端口为本地127,需要手动配置个nginx转发访问。
首次访问konga会先要求注册一个管理员用户,然后配置kong admin连接:
赏
使用支付宝打赏
使用微信打赏
若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏