【问题标题】:Kong - custom plugins returning: custom-plugin plugin is enabled but not installed;Kong - 自定义插件返回:自定义插件插件已启用但未安装;
【发布时间】:2019-11-19 23:35:14
【问题描述】:

我有一个使用 Dockerfile 运行的 Kong 实例,其中包含内容:

FROM kong:1.4.0

WORKDIR /files
COPY plugins kong/plugins
ENV KONG_LOG_LEVEL=debug
ENV KONG_PLUGINS custom-plugin
ENV KONG_LUA_PACKAGE_PATH /files/?.lua;;

但是,在 docker run 上,这会返回

error loading plugin schemas: on plugin 'custom-plugin': custom-plugin plugin is enabled but not installed;

module 'kong.plugins.custom-plugin.handler' not found:No LuaRocks module found for kong.plugins.custom-plugin

我已确认文件结构正确,运行时嵌套在 kong/plugins 目录中。

谁能帮忙解决这个问题?

【问题讨论】:

    标签: docker dockerfile kong


    【解决方案1】:

    查看这些资源:

    来自 Kong 的错误报告: https://github.com/Kong/kong/issues/4696

    I don't think it's the luarocks' problem
    Indeed, I installed kong in docker whose image is built by a dockerfile.
    In my docker file, I went into the folder which store the custom plugins,and then traverse and luarocks make them by shell.It looks like:
    
    #install private plugins
    cd APIGPlugins
    
    for dir in `ls`; do
        if [ -d $dir ]; then
          cd $dir;
          luarocks make;
          cd ../;
        fi
    done
    and then, I run the docker images for a container by the directive:
    
    sudo docker run -d --name kong \
        -e "KONG_DATABASE=off" \
        -e "KONG_DECLARATIVE_CONFIG=/etc/kong/kong.yml" \
        -e "KONG_PLUGINS=apig-response-transform" \
        -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
        -p 8000:8000 \
        -p 8443:8443 \
        -p 8001:8001 \
        -p 8444:8444 \
        kong-plugin:v4
    As u see, I set the kong plugin by the docker run env variable parameter for enable the plugin instead of setting in the kong.conf.
    The logs were generated by directive of docker logs "container ID"
    It works when I tried to install another custom plugin in this way,but not work when install the custom plugin I described before
    

    更新

    你需要安装lua包管理器luarocks

    【讨论】:

    • 感谢您的回答。我尝试按上述方式运行解决方案,但luarocks make 行抛出:缺少参数:请指定要在当前目录上使用的rockspec。我在 plugins/custom-plugin 目录中运行它,我也在 custom-plugin 中尝试过,但我得到了同样的错误。
    • 你需要安装lua包管理器luarocks : Documentaton Link | Download Link
    • 答案已更新,请参阅答案末尾。
    【解决方案2】:

    查看来自Kong/kong-plugin-zipkin issue 5(另一个依赖于kong.plugins.custom-plugin.handler 的插件)的指令之一是否适用于kong.plugins.custom-plugin.handler 本身。

    它的要点是该插件应该在磁盘上可供 Kong 使用,并添加到 custom_plugins 配置属性中。

    您可以通过多种方式实现这一目标:

    不要忘记您也可以使用环境变量指定配置 Kong,因此使用 -e KONG_CUSTOM_PLUGINS=my-custom-plugin 也可以。

    插件还需要位于LUA_PATH 中(类似于 PATH,但适用于 Lua 模块)。

    因此,简而言之,一种可能的解决方案是使用卷和环境变量:

    • 挂载插件代码:-v /path/to/my-custom-plugin:/etc/kong/plugins/my-custom-plugin
    • 将包含自定义插件的目录添加到LUA_PATH-e KONG_LUA_PACKAGE_PATH=/etc/?.lua(Kong 需要kong.plugins.custom-plugin.handler,转换为/etc/kong/plugins/my-custom-plugin/handler.lua
    • 指示 Kong 加载插件:-e KONG_CUSTOM_PLUGINS=my-custom-plugin

    接着,首先检查这是否是KONG_LUA_PATH 问题,如Kong/kong issue 3394

    这是关于插件迁移的,但也可能在这里产生影响。

    作为一个短期解决方案,您应该将您的 LUA_PATH 环境变量设置为指向您的自定义插件的安装路径
    (而不是 kong.confKONG_LUA_PACKAGE_PATH 中的 lua_package_path)。

    例如我刚搬家:

    export KONG_LUA_PACKAGE_PATH="/path/to/some-custom-plugin/?.lua;;"
    

    到:

    export LUA_PATH="/path/to/some-custom-plugin/?.lua;$LUA_PATH"
    

    然后再次运行kong migrations up,成功运行了插件的迁移。

    那是因为lua_package_path 仅适用于运行时 Kong(在 nginx 内),并且 CLI 不考虑(kong migrations 命令)

    如果我只是在kong.conf 中评论lua_package_path 并按照您提到的那样导出LUA_PATH,它开始给我这个错误:

    ./kong:3: module 'luarocks.loader' not found:
    

    我从中执行 kong 迁移的 shell 从未设置过 LUA_PATH,甚至在此之前。如果尚未在 shell 中设置 LUA_PATH,则它似乎会在内部创建 LUA_PATH

    所以我必须执行的附加步骤是通过运行“luarocks path”命令获取内部设置的当前LUA_PATH,然后获取结果,并将我的自定义登录插件路径附加到它,然后导出LUA_PATH 让它工作。

    同样,即使您当前的问题与迁移无关,其中一个变量可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-06-15
      • 1970-01-01
      • 2021-11-04
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2017-01-10
      相关资源
      最近更新 更多