kong网关的使用

复制代码
关于docker的kong详情https://cloud.tencent.com/developer/article/2339527
和自定义插件https://blog.csdn.net/whos2016/article/details/103034883
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=kong" \
 -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
 -e "KONG_ADMIN_ACCE_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" \
 -e "KONG_ADMIN_GUI_URL=http://localhost:8002" \
 -e "KONG_PLUGIN_PATH=/kong/plugins/?.lua;;" \
 -e "KONG_LUA_PACKAGE_PATH=/kong/plugins/my-first-plugin/?.lua;;" \
 -e "KONG_PLUGINS=bundled,my-first-plugin" \
 -e "KONG_CUSTOM_PLUGINS=my-first-plugin" \
 -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
 -e "KONG_LOG_LEVEL=debug" \
 -p 8000:8000 \
 -p 8443:8443 \
 -p 8001:8001 \
 -p 8444:8444 \
 -p 8002:8002 \
 -p 8445:8445 \
 -p 8003:8003 \
 -p 8004:8004 \
 kong/kong-gateway:latest


#带有映射目录的容器
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=kong" \
 -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
 -e "KONG_ADMIN_ACCE_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" \
 -e "KONG_ADMIN_GUI_URL=http://localhost:8002" \
 -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
 -e "KONG_LOG_LEVEL=debug" \
 -v "/root/workspace/my-plugins:/kong/plugins" \
 -v "/root/workspace/etc/kong:/etc/kong" \
 -v "/root/workspace/lua_kong/kong:/usr/local/share/lua/5.1/kong" \
 -p 8000:8000 \
 -p 8443:8443 \
 -p 8001:8001 \
 -p 8444:8444 \
 -p 8002:8002 \
 -p 8445:8445 \
 -p 8003:8003 \
 -p 8004:8004 \
 kong/kong-gateway:latest

## 指定一个目录存放kong容器的内容,这个有三个部分 自定插件,kong配置 和lua脚本
mkdir etc lua_kong
docker cp ${container_id}:/etc/kong etc/kong # ${container_id} 换成容器ID,下同
docker cp ${container_id}:/usr/local/share/lua/5.1/kong lua_kong/kong  # 

关于自定义插件内容可以参考文章

手把手教你实现一个Kong网关插件-腾讯云开发者社区-腾讯云

有关问题,进入kong容器内部,修改的配置文件无效被覆盖:因为kong会生成自己定义的配置文件去启动nginx,所以你在/usr/local/kong中的nginx-kong.conf修改的内容是生成式的,每次启动就没了,使用kong启动一个nginx的server方式很简单,在宿主机新建文件,具体内容参考

Kong配置项向导 - 简书 注意添加一个服务器指定的端口是在容器内部,如果kong没有暴露该接口对外是访问不了,你可以该8001然后定义一个路由返回内容

复制代码
server {
    listen 8001; ## 指定端口kong容器一定暴露在宿主机
    location /sayHello {
      return 200 "服务正在升级,请稍后再试8001 ,你想使用kong开启8009服务器提供服务担是该端口是容器内部没有暴露>出来";
    }
}

这些就能使你的kong像nginx和openresty一样工作和设置了。

相关推荐
呆呆敲代码的小Y5 天前
Lua 上值(UpValue)
开发语言·junit·lua·lua上值·upvalue
呆呆敲代码的小Y5 天前
【游戏开发】xLua 性能优化技巧
junit·性能优化·lua·xlua
nvd115 天前
实战:用 Lua 手写 Kong 安全鉴权插件并通过 ArgoCD GitOps 零编译部署到 DbGate 服务
安全·lua·kong
lhldsg8 天前
家政派单系统开发实战:从需求分析到智能调度全流程指南
java·junit·小程序·uni-app·需求分析
肠畔码农11 天前
深度解密 Redis 核心引擎:从 MULTI/EXEC 事务机制到 EVAL 脚本的原子性演进
数据库·redis·junit
会编程的吕洞宾13 天前
Spring Cloud Gateway限流:Redis令牌桶防刷实战
数据库·redis·junit
難釋懷15 天前
Nginx-Lua
nginx·junit·lua
萧瑟余晖16 天前
Java深入解析篇三十七之JUnit 5 详解
java·junit
骑士雄师18 天前
superpowers使用流程
junit·skill
重庆小透明19 天前
深入探寻微服务【第五篇微服务限流实战】
微服务·junit·架构