【发布时间】:2020-10-01 12:06:33
【问题描述】:
我在 docker 中以声明模式使用 kong。
我想从这里尝试插件 kong-jwt2header: https://docs.konghq.com/hub/yesinteractive/kong-jwt2header/
我按照kong.yml中的描述进行了配置:
plugins:
- name: kong-jwt2header
config:
strip_claims: false
token_required: true
我将一个插件文件夹链接到 docker 容器中:
version: '3'
services:
kong:
container_name: kong
image: kong:2.1.3-centos
environment:
- KONG_DATABASE=off
- KONG_DECLARATIVE_CONFIG=/usr/local/kong/declarative/kong.yml
- KONG_PROXY_ACCESS_LOG=/dev/stdout
- KONG_ADMIN_ACCESS_LOG=/dev/stdout
- KONG_PROXY_ERROR_LOG=/dev/stderr
- KONG_ADMIN_ERROR_LOG=/dev/stderr
- KONG_CUSTOM_PLUGINS=kong-jwt2header
- KONG_ADMIN_LISTEN=0.0.0.0:7001, 0.0.0.0:7444 ssl
- KONG_LOG_LEVEL=${KONG_LOG_LEVEL:-info}
volumes:
- ./kong.yml:/usr/local/kong/declarative/kong.yml
- ./plugins:/usr/local/kong/plugins
ports:
- 7000:8000
- 7001:7001
- 7443:8443
- 7444:7444
在启动时,我收到需要启用插件的异常。
2020/10/01 11:45:08 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:491: error parsing declarative config file /usr/local/kong/declarative/kong.yml:
in 'services':
- in entry 2 of 'services':
in 'plugins':
- in entry 1 of 'plugins':
in 'name': plugin 'kong-jwt2header' not enabled; add it to the 'plugins' configuration property
stack traceback:
[C]: in function 'error'
/usr/local/share/lua/5.1/kong/init.lua:491: in function 'init'
init_by_lua:3: in main chunk
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:491: error parsing declarative config file /usr/local/kong/declarative/kong.yml:
in 'services':
- in entry 2 of 'services':
in 'plugins':
- in entry 1 of 'plugins':
in 'name': plugin 'kong-jwt2header' not enabled; add it to the 'plugins' configuration property
stack traceback:
[C]: in function 'error'
/usr/local/share/lua/5.1/kong/init.lua:491: in function 'init'
init_by_lua:3: in main chunk
在网上搜索时,我发现了这个: https://github.com/Kong/docker-kong/issues/227
他们写道,我必须将其添加到 kong.conf 文件中的 //plugins// 变量中,如插件开发指南中所述。 (https://docs.konghq.com/1.1.x/plugin-development/distribution/#load-the-plugin)
我尝试在 docker-compose 中设置它
- KONG_CUSTOM_PLUGINS=kong-jwt2header
没有成功。
我在 docker_compose.yml 中设置了环境变量
- KONG_PLUGINS=bundled,kong-jwt2header
现在我得到一个新的异常,它说插件 kong-jwt2header 已启用但未安装。
我在 /etc/kong/ 中的容器内找到了 kong.conf.defaults 并将其复制到外部并添加了属性插件,如 docker 指南中所述,并安装到容器中。
现在我得到了这个异常:
2020/10/01 12:33:09 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:484: error loading plugin schemas: on plugin 'kong-jwt2header': kong-jwt2header plugin is enabled but not installed;
module 'kong.plugins.kong-jwt2header.handler' not found:No LuaRocks module found for kong.plugins.kong-jwt2header.handler
no field package.preload['kong.plugins.kong-jwt2header.handler']
现在我已经没有想法了。 (除了在没有 docker 和没有声明性方法的情况下尝试它)
如何使用声明性配置将自定义插件添加到 docker 容器内的 kong?
【问题讨论】:
标签: docker docker-compose kong