如何将自定义的 kong 插件添加到 dockerized kong

How can I add a customized kong plugin into dockerized kong

我有一个 KONG 容器 运行,我想给它添加一个自定义插件,特别是 JWT crafter。 我已经下载了该插件,但我不知道如何使用我的 KONG 容器启动它。因此,如果有人处于相同的位置或知道任何可遵循的路线,那将非常有帮助。

我尝试做同样的事情,但还没有找到 well-describe 答案。 您可以按如下方式配置简单的 helloworld 插件:(https://github.com/brndmg/kong-plugin-hello-world)

Docker 上的本地 'plugin' 目录结构 host:

然后你可以挂载本地 /plugins 目录并让 kong 从 /plugins 目录加载自定义 'helloworld' 插件

1) 使用环境变量

$ docker run -d --name kong --network=kong-net \
-e "KONG_DATABASE=cassandra" \
-e "KONG_PG_HOST=kong-database" \ 
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
**-e "KONG_LUA_PACKAGE_PATH=/plugins/?.lua" \
-e "KONG_CUSTOM_PLUGINS=helloworld" \ ** 
...
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
**-v "/plugins:/plugins" \**
-p 8080:8000 -p 8443:8443 -p 8001:8001 -p 8444:8444 kong:latest

然后就可以在http://[kong-url]:8001/

上看到配置好的自定义插件了
..
"custom_plugins": [
"helloworld"
],
..

2) 或者,您可以简单地挂载描述您想要的插件的自定义 kong.conf 文件。

/etc/kong/kong.conf

plugins = bundled,helloworld,jwt-crafter

(似乎第二个选项对最新版本的 Kong 更好,因为 'kong_custom_plugin' 配置打印 'deprecation' 警告)

对于 JWT 工匠,https://github.com/foodora/kong-plugin-jwt-crafter 貌似插件没有维护好导致使用luarocks安装失败报错

$ luarocks install kong-plugin-jwt-crafter
....
kong-plugin-jwt-crafter 1.0-0 depends on lua-resty-jwt ~> 0.1.10-1 (not installed)

Error: Could not satisfy dependency lua-resty-jwt ~> 0.1.10-1: No results matching query were found.

也可以直接在官方docker镜像中添加'resty-jwt',解决官方镜像不包含的依赖。并将 "JWT crafter" 复制到“/plugins”目录,然后加载。

(在 docker 容器内)

 luarocks install lua-resty-jwt

希望这对您有所帮助。

您可以使用 https://github.com/Kong/docker-kong/tree/master/customize

生成包含插件的新 docker 图像

查看示例 (https://github.com/Kong/docker-kong/blob/master/customize/example.sh),了解如何在 LuaRocks 上公开源代码的情况下执行此操作。

我建议使用 this repository's 示例来使用自定义插件构建 Kong docker 图像。