Kong Plugin with Dependencies in Kubernetes


I have a Plugin I’d like to install in my Kong instance which is running on Kubernetes.
After reading this: https://github.com/Kong/kubernetes-ingress-controller/blob/master/docs/guides/setting-up-custom-plugins.md
the Plugin was starting to load by Kong. Unfortunately it breaks then, because I have a dependency to resty.openidc which is not installed.

So how do I install those missing dependencies?
I tried to install the dependency as a Kong Plugin, but it’s missing a handler.lua and breaks because of this.
I tried to put the dependency in a subdirectory and adjusted the require() calls, but resty.openidc itself has also dependencies, which would also have to be adjusted.

Someone mentioned, that it would be possible with a InitContainer. How would that work, when my installation is done with Helm?

Thank you!

Yep–this is kind of a necessary limitation between what ConfigMaps offer and what installing plugins entails when it has dependencies.

There is the subdirectory loader in the Helm chart, but it sounds like you’ve already tried that without success.

If that doesn’t provide a good way for you to include all requirements, you’ll probably want to look at creating a custom Kong image that installs the plugin(s) via LuaRocks. Since LuaRocks has its own Lua-aware dependency management, it’s able to install plugins and their dependencies more intelligently than the ConfigMap-based loader. Building the custom image will require that you create a Dockerfile that’s something along the lines of

FROM kong:2.0.4

RUN ["luarocks", "install", "pluginname"]

The resulting image will include both the plugin and its dependencies in the correct location, and you can load it into a private registry for use in your Kubernetes cluster.

The ConfigMap-based loader is useful for simpler plugins that only require their own code (and libraries that are already in the image by default)–more complex plugins with other external dependencies can sometimes load through the ConfigMap loader, but will often be easier to handle with custom images. I’ll note down that we should update our docs to cover both methods.

I have similar issue, I have a DB mode deployment on Kubernetes with helm, I am still unable to add dependencies. The packages that I am trying to use has multiple inner dependencies. Do we have solution for this ?

Error message
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:64: nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/tools/utils.lua:707: error loading module ‘kong.plugins.kong-sql-injection.handler’:

/opt/kong/plugins/kong-sql-injection/access.lua:1: module ‘resty.injection’ not found:No LuaRocks module found for resty.injection

Any suggestions to handle this gracefully?

A custom image similar to what’s shown in my previous post is still my standard recommendation when you have dependencies.

Running the installer in an initContainer is another option, but IMO it’s a worse one:

  • The install happens at Pod instantiation time, so Pods will start more slowly, and can potentially fail if there’s some issues pulling down packages.
  • Updates to the custom plugins do not modify the Deployment, so they will not roll out automatically.
  • Unexpected Pod restarts (e.g. due to a reschedule) can potentially pull down a different version of the plugin, resulting in a Deployment whose Pods aren’t running the same set of code.

The latter two issues can be mitigated by pinning the version the install command uses, but there’s no way to avoid the first.

For creating images that have custom plugins or custom config templates, see docker-kong/customize at master · Kong/docker-kong · GitHub

© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ