Docker-compose构建微服务 kong网关

Posted 年少~年

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker-compose构建微服务 kong网关相关的知识,希望对你有一定的参考价值。

1.创建docker-compose.yml文件

version: "3.0"
networks:
 kong:
  driver: bridge
services:
 postgres:
  image: postgres:11.11   #tag高于12 konga-prepare 容器启动报错
  restart: always
  container_name: postgres
  hostname: postgres
  ports:
   - 5432:5432
  environment:
   - "POSTGRES_USER=postgres"
   - "POSTGRES_DB=kong"
   - "POSTGRES_PASSWORD=postgres"
  volumes:
   - /var/docker-compose-config/kong:/var/lib/postgresql/data
  networks:
   - kong
 #执行数据库迁移初始化表
 kong-migration:
  image: kong:2.3
  command: "kong migrations bootstrap"
  container_name: kong-migration
  hostname: kong-migration
  restart: on-failure
  links:
  - "postgres:postgres"
  environment:
  - "KONG_DATABASE=postgres"
  - "KONG_PG_USER=postgres"
  - "KONG_PG_DATABASE=kong"
  - "KONG_PG_HOST=postgres"
  - "KONG_PG_PASSWORD=postgres"
  - "KONG_CASSANDRA_CONTACT_POINTS=postgres"
  depends_on:
   - postgres
  networks:
   - kong
 kong:
  image: kong:2.3
  restart: always
  container_name: kong
  hostname: kong
  links:
   - "postgres:postgres"
  environment:
   - "KONG_DATABASE=postgres"
   - "KONG_PG_USER=postgres"
   - "KONG_PG_DATABASE=kong"
   - "KONG_PG_HOST=postgres"
   - "KONG_PG_PASSWORD=postgres"
   - "KONG_CASSANDRA_CONTACT_POINTS=postgres"
   - "KONG_PROXY_LISTEN=0.0.0.0:8000"
   - "KONG_PROXY_LISTEN_SSL=0.0.0.0:8443"
   - "KONG_ADMIN_LISTEN=0.0.0.0:8001"
  depends_on:
   - postgres
   - kong-migration
  ports:
   - 8001:8001
   - 8000:8000
   - 8443:8443
  depends_on:
   - postgres
  networks:
   - kong
 konga-prepare:
  image: pantsel/konga:0.14.9
  #postgresql://postgres[用户]:postgres[密码]@postgres[ip]:5432/kong
  command: "-c prepare -a postgres -u postgresql://postgres:postgres@postgres:5432/kong"
  restart: on-failure
  container_name: konga-prepare
  hostname: konga-prepare
  environment:
   - "DB_ADAPTER=postgres"
   - "DB_HOST=postgres"
   - "DB_PORT=5432"
   - "DB_USER=postgres"
   - "DB_PASSWORD=postgres"
   - "DB_DATABASE=kong"
   - "NODE_ENV=development"
  links:
   - "postgres:postgres"
  depends_on:
   - postgres
   - kong-migration
  networks:
   - kong
 konga:
  image: pantsel/konga:0.14.9
  restart: always
  container_name: konga
  hostname: konga
  environment:
   - "DB_ADAPTER=postgres"
   - "DB_HOST=postgres"
   - "DB_PORT=5432"
   - "DB_USER=postgres"
   - "DB_PASSWORD=postgres"
   - "DB_DATABASE=kong"
   - "NODE_ENV=development"
  links:
   - "postgres:postgres"
  depends_on:
   - kong
   - konga-prepare
   - postgres
   - kong-migration
  ports:
   - "1337:1337"
  networks:
   - kong
  1. 执行
docker-compose up 


3. 访问

http://ip:1337访问

系统架构


kong依赖数据库,一般使用postgres,默认端口为
接受客户端流程端口

8000:http
8443:https
Admin Api端口:

8001:http
8444:https
kong的配置信息都是通过API接口控制
信息获取使用: GET
创建:POST
更新:PATCH
删除:DELETE
功能api使用
route: client请求入口
server: 后端服务的抽象层,维护route与upstream之间的映射关系,
upstream: 托管后端服务器
plugin: 作用整个流量代理周期

以上是关于Docker-compose构建微服务 kong网关的主要内容,如果未能解决你的问题,请参考以下文章

网关服务Kong、Konga搭建记录

spring cloud 与 docker-compose构建微服务

微服务之kong+consul

kong 集成微服务的用户注册+认证

微服务网关方案:Kong & Nacos

微服务Kong——代理参考