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一样工作和设置了。

相关推荐
Hello.Reader10 小时前
Redis性能基准测试
数据库·redis·junit
_GR12 小时前
一篇博客学习Lua_安装使用+语法详解
开发语言·junit·lua
qq_433888933 天前
Junit多线程的坑
java·spring·junit
freesharer8 天前
kong网关基于header分流灰度发布
kong
艺杯羹22 天前
Maven 之 JUnit 测试体系构建全解析
java·junit·maven
转码的小石23 天前
深入Java大厂面试:从Spring框架到微服务架构的技术解析
java·spring boot·spring cloud·微服务·junit·spring security·hibernate
专注代码七年25 天前
Spring Boot单元测试终极指南:从环境搭建到分层测试实战
java·spring boot·junit
xiaoxi6661 个月前
用好 JUnit 5 的高级特性:提升单测效率和质量
junit
什么都想学的阿超1 个月前
【Redis系列 03】掌握Redis编程艺术:事务、管道与Lua脚本完全指南
redis·junit·lua
爱瑞瑞1 个月前
Junit5测试类编写笔记
junit