我在声明模式中使用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容器内?
发布于 2020-11-16 06:46:18
你需要在容器内安装带有luarock的插件。
USER root
RUN apk update && apk add git unzip luarocks
RUN luarocks install kong-oidc
USER kong如果您使用基于阿尔卑斯的kong-latest,则可以使用该示例。
https://stackoverflow.com/questions/64155056
复制相似问题