While adding a custom plugin to Kong in Kubernetes it fails to start with the next error:
2023/12/18 11:41:51 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/tools/utils.lua:786: error loading module 'kong.plugins.custom-rate-limit.handler':
93
/opt/kong/plugins/custom-rate-limit/handler.lua:2: module 'lunajson' not found:No LuaRocks module found for lunajson
92
no field package.preload['lunajson']
As I understand, the default Kong image doesn’t have lunajson module and that’s why it complains about it.
How can I add a missed module - updating the default Kong image?
@cactus You need to create a custom image with the dependencies added. This will increase the size of the image - if you find any other alternatives to bring back the size, please do respond here (I am looking for a solution)
FROM kong/kong-gateway:3.4
USER root
RUN apt-get update
RUN apt-get install -y lua5.1 luarocks
#RUN apk add gcc expat expat-dev expat-static musl-dev
RUN luarocks install lua-cjson 2.1.0.6-1 # add your dependency here
RUN luarocks install xml2lua 1.5-2
USER kong
WORKDIR /usr/local/share/lua/5.1/kong/plugins
COPY kong/plugins/ ./
Also, a plugin was added to Kubernetes using Kind: KongPlugin, according to this manual.
Plugin is available, but when we tried to use it(add annotation to service or route), we got the error:
proxy 2023/12/20 17:20:52 [debug] 1262#0: *311 [lua] init.lua:23: poll(): worker-events: emulate poll method │
│ proxy 2023/12/20 17:20:52 [error] 1262#0: *311 [lua] api_helpers.lua:540: handle_error(): /usr/local/share/lua/5.1/lapis/application.lua:439: /usr/local/share/lua/5.1/kong/db/schema/init.lua:1204: attempt to index a nil │
│ value │
│ proxy stack traceback: │
│ proxy /usr/local/share/lua/5.1/kong/db/schema/init.lua: in function 'run_entity_check' │
│ proxy /usr/local/share/lua/5.1/kong/db/schema/init.lua:1321: in function 'run_checks' │
│ proxy /usr/local/share/lua/5.1/kong/db/schema/init.lua:1355: in function 'run_entity_checks' │
│ proxy /usr/local/share/lua/5.1/kong/db/schema/init.lua:1986: in function 'validate_upsert' │
│ proxy /usr/local/share/lua/5.1/kong/db/dao/init.lua:596: in function 'check_upsert' │
│ proxy /usr/local/share/lua/5.1/kong/db/dao/init.lua:1211: in function 'upsert_entity' │
│ proxy /usr/local/share/lua/5.1/kong/api/endpoints.lua:499: in function 'fn' │
│ proxy /usr/local/share/lua/5.1/kong/api/api_helpers.lua:311: in function </usr/local/share/lua/5.1/kong/api/api_helpers.lua:289> │
│ proxy │
│ proxy stack traceback: │
│ proxy [C]: in function 'error' │
│ proxy /usr/local/share/lua/5.1/lapis/application.lua:439: in function 'handler' │
│ proxy /usr/local/share/lua/5.1/lapis/application.lua:185: in function 'resolve' │
│ proxy /usr/local/share/lua/5.1/lapis/application.lua:216: in function </usr/local/share/lua/5.1/lapis/application.lua:214> │
│ proxy [C]: in function 'xpcall' │
│ proxy /usr/local/share/lua/5.1/lapis/application.lua:214: in function 'dispatch' │
│ proxy /usr/local/share/lua/5.1/lapis/nginx.lua:231: in function 'serve' │
│ proxy /usr/local/share/lua/5.1/kong/init.lua:1626: in function 'admin_content' │
│ proxy content_by_lua(nginx-kong.conf:330):2: in main chunk, client: 10.15.64.85, server: kong_admin, request: "PUT /plugins/470bfd5f-6718-497b-a638-67da79a0ee2d HTTP/2.0", host: "10.15.67.7:8444" │
│ proxy 2023/12/20 17:20:52 [debug] 1262#0: *311 [lua] init.lua:23: poll(): worker-events: emulate poll method
This custom plugin was written for kong-2.1(also postgres was used as db for kong), we are trying to use it on kong-3.4 in kubernetes in db-less mode.
What is the best way to import plugins from old kong version into new one?