如何在dockerized kong中添加自定义的kong插件

时间:2018-05-17 12:13:56

标签: docker dockerfile kong api-gateway

我有一个KONG容器正在运行,我想为它添加一个自定义插件,特别是JWT crafter。 我已经下载了该插件,但我不知道如何从我的KONG容器开始。所以,如果有人进入同一职位或知道任何可以遵循的路线,那将非常有帮助。

3 个答案:

答案 0 :(得分:2)

我试图做同样的事情,但是找不到描述正确的答案。 您可以如下配置简单的helloworld插件:(https://github.com/brndmg/kong-plugin-hello-world

Docker主机上的本地“插件”目录结构:

plugin directory structure

然后您可以挂载本地/ 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'配置会显示'depremination'警告)

对于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.

相反,您可以直接将'resty-jwt'添加到官方docker映像中,以解决依赖关系,该依赖关系未包含在官方映像中。并将“ JWT Crafter”复制到“ / plugins”目录,然后加载。

(在docker容器内部)

 luarocks install lua-resty-jwt

希望这会有所帮助。

答案 1 :(得分:1)

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

答案 2 :(得分:0)

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

生成一个包含插件的新docker映像。