Install Kong with a Database and Custom Values Using Helm by Fetching Chart Locally.

Shantanu Dey Anik
5 min readMar 18, 2024

--

Kong API Gateway is a versatile open-source solution for managing microservices architectures. Serving as a centralized entry point, it streamlines API traffic management, enhances security, and optimizes performance. With its extensive plugin ecosystem and scalability, Kong empowers developers to build resilient, agile applications in any environment.

Today, I will explain how we can deploy Kong to Kubernetes with a database. In this write-up, we will deploy it using Helm.

So, why a database? With a database, we can store multiple route configurations persistently. Additionally, with a database, we can use dashboards like Kong OSS Manager to work with Kong API in GUI mode.

Since Kong prefers PostgreSQL as its database, let’s create a user and database for Kong in PostgreSQL.

User and Database Creation

As we’re deploying Kong using the Helm chart, we’ll need to make adjustments and work with the chart and its values. Now, we will select a working directory. I am working in /opt.

helm repo add kong https://charts.konghq.com
helm repo update
helm search repo kong/ingress
helm fetch kong/ingress

This will download a gzip-compressed tar file in the current directory, which can be named ingress-0.xx.x.tgz

After Extracting the tar file and replacing “xx” with the appropriate version that we downloaded.

tar xvf ingress-0.xx.x.tgz

Inside, you’ll find a values.yaml file where we will configure the database and other settings as needed.

We can set the environment variables with values we have created earlier (example):

env:
role: traditional
database: postgres
pg_host: 172.19.0.7
pg_port: 5432
pg_user: kong
pg_password: kong_password
pg_database: kong_db
pg_schema: public
values.yaml

The Kong Ingress chart inherits values from the Kong chart kong/kong, allowing for further customization. If any additional changes are needed, they can be made in the charts/kong/values.yaml file. Here, you can specify additional environment variables, change the image version, expose ports, and more.

After modifying the files in the extracted folder, proceed to run the installation command.

helm install kong . -n kong --create-namespace
Kong install using helm

This command will deploy Kong with the specified database configuration.

Keep in mind that the ‘kong-gateway-init-migration’ pod will connect to the database and create the required tables. If it fails to connect with the database, it will continuously restart. Therefore, other pods will not work until it completes its task. Be sure to monitor the logs of that pod.

Now, after all pods are running successfully, let’s check if the service is accessible or not.

Let’s make a curl request to the NodePort of the service named Kong-gateway-Proxy and check if a response is coming or not. Since we haven’t configured any ingress or routes to Kong yet, the response will look like this.

Now that our Kong installation is complete, let’s explore the Kong OSS Manager.

Firstly, port-forward the kong-gateway-admin service with the same port as the service, which is typically 8444 by default. This is necessary because Kong OSS Manager requires HTTPS and will request to port 8444. Avoid using any random port. In this example, I am using Lens to access the cluster.

Using CLI to port-forward kong-gateway-admin :-

kubectl port-forward --address 0.0.0.0 service/kong-gateway-admin -n kong 8444:8444

This port forward exposes the Kong admin API to port 8444. We can access it using either localhost or the master IP address

Now port forward the kong-gateway-manager to any random port with https.

Using CLI to port-forward kong-gateway-manager:-

kubectl port-forward --address 0.0.0.0 service/kong-gateway-manager -n kong 8445:8445

This port forward exposes the Kong gateway manager to port 8445. We can access it using either localhost or the master IP address.

Remember, if you don’t expose the kong-gateway-admin service to port 8444, the Kong Manager won’t display any details on this page. This means that it won’t work properly.

Using the Kong Manager, we can enhance the functionality and security of our deployed application by adding gateway services, routes, consumers, and various types of plugins. This allows us to ensure security and reliability while efficiently managing API traffic and configurations.

In conclusion, deploying Kong with a database using Helm provides a powerful API gateway solution for managing microservices architectures. By customizing the values.yaml file and ensuring proper port forwarding for the Kong admin API, we can effectively configure and access Kong OSS Manager to manage APIs with ease. This setup enhances security, scalability, and performance for applications deployed in Kubernetes environments.

Ref:

--

--

Responses (1)