DEV Community

Zelar for Zelarsoft

Posted on • Updated on

Installing Custom Plugins in Kong API Gateway on Kubernetes: Helm Deployment in Hybrid Mode

By Venkata Reddy Bhavanam
Author LinkedIn: https://www.linkedin.com/in/venkatareddybhavanam/

This is the 3rd post on installing custom plugins in Kong API Gateway. Please check out the first post for a quick introduction to Kong and installing a custom plugin in VM mode.

In this post, we’ll learn how to install a custom plugin deployed using Helm in Hybrid mode in Kubernetes, but this should also work in other modes of deployment in Kubernetes.

A custom plugin can be installed in Kong and deployed in Kubernetes in two ways.

1.Building a custom image by adding the plugin code to the Kong base image. This will be useful when our plugin needs a dependency at the OS level.

2.Adding the plugin as k8s ConfigMap or Secret. This is probably the easiest of two, as we don’t have to maintain the image in a custom container registry.

For #1, you can check how we can build the image in the last post of this series. Once the image is created, assuming the Kong gateway is deployed using helm, we can add the updated image with the tag in the values-cp.yaml and values-dp.yaml

We’ll use the same plugin api-version that we used in the last post.

First, we must create a Kubernetes secret for pulling the custom Kong image from our private docker registry. Assuming we have our image in GHCR, we can do the following:

kubectl create secret docker-registry your-secret-name-to-be-able-pull-image-from-cr --docker-server=ghcr.io --docker-username=your-user --docker-password=your-passwrod --docker-email=your-email -n your-namespace
Enter fullscreen mode Exit fullscreen mode

Then, update the values-cp.yaml and values-dp.yaml With the following values:

repository: ghcr.io/zelarhq/kong/kong-gateway
tag: "3.2.2.1.api-version.01" # Should change this image as per company standards, refer to supported image tags https://hub.docker.com/r/kong/kong-gateway/tags
pullSecrets:
  - your-secret-name-to-be-able-pull-image-from-cr

env:
  plugins: "bundled,api-version"

...
Enter fullscreen mode Exit fullscreen mode

And upgrade CP and DP with:

helm upgrade --install kong-cp kong/kong --namespace kong-enterprise -f values-cp.yaml
helm upgrade --install kong-dp kong/kong --namespace kong-enterprise -f values-dp.yaml
Enter fullscreen mode Exit fullscreen mode

To enable the plugin, it should appear in the Kong Manager under the Plugins section.

For #2, create a k8s Secret,

kubectl create secret generic -n <namespace_name> kong-plugin-api-version --from-file=kong-plugin-api-version

OR a ConfigMap

kubectl create configmap kong-plugin-api-version --from-file=kong-plugin-api-version -n <namespace_name>

Update the values-cp.yaml and values-dp.yaml files with the following content:

Plugins:

secrets: #configMaps -> if using config map
  - name: kong-plugin-api-version
    pluginName: api-version
Enter fullscreen mode Exit fullscreen mode

And upgrade CP and DP with:

helm upgrade --install kong-cp kong/kong --namespace <your-namespace> -f values-cp.yaml
helm upgrade --install kong-dp kong/kong --namespace <your-namespace> -f values-dp.yaml
Enter fullscreen mode Exit fullscreen mode

For more information: https://zelarsoft.com/

Top comments (0)