Install Kong Gateway
This guide explains how to deploy Kong Gateway on Kubernetes without using Kong Konnect or Kong Ingress Controller.
Kong Konnect is recommended for new installations to reduce deployment complexity.
Let Kong run the control plane and database for you. With Kong Konnect, you only need to run the data planes. Get started in under 5 minutes.
These instructions configure Kong Gateway to use separate control plane and data plane deployments. This is the recommended production installation method.
Prerequisites
Helm Setup
Kong provides a Helm chart for deploying Kong Gateway. Add the charts.konghq.com
repository and run helm repo update
to ensure that you have the latest version of the chart.
helm repo add kong https://charts.konghq.com
helm repo update
Secrets
Kong Gateway Enterprise License
First, create the kong
namespace:
kubectl create namespace kong
Next, create a Kong Gateway Enterprise license secret:
Ensure you are in the directory that contains a
license.json
file before running this command.
kubectl create secret generic kong-enterprise-license --from-file=license=license.json -n kong
Clustering Certificates
Kong Gateway uses mTLS to secure the control plane/data plane communication when running in hybrid mode.
-
Generate a TLS certificate using OpenSSL.
openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout ./tls.key -out ./tls.crt -days 1095 -subj "/CN=kong_clustering"
-
Create a Kubernetes secret containing the certificate.
kubectl create secret tls kong-cluster-cert --cert=./tls.crt --key=./tls.key -n kong
Installation
Control Plane
The control plane contains all Kong Gateway configurations. The configuration is stored in a PostgreSQL database.
-
Create a
values-cp.yaml
file. -
(Optional) If you want to deploy a Postgres database within the cluster for testing purposes, add the following to the bottom of
values-cp.yaml
.# This is for testing purposes only # DO NOT DO THIS IN PRODUCTION # Your cluster needs a way to create PersistentVolumeClaims # if this option is enabled postgresql: enabled: true auth: password: demo123
-
Update the database connection values in
values-cp.yaml
.-
env.pg_database
: The database name to use -
env.pg_user
: Your database username -
env.pg_password
: Your database password -
env.pg_host
: The hostname of your Postgres database -
env.pg_ssl
: Use SSL to connect to the database
-
-
Set your Kong Manager super admin password in
values-cp.yaml
.-
env.password
: The Kong Manager super admin password
-
-
Run
helm install
to create the release.helm install kong-cp kong/kong -n kong --values ./values-cp.yaml
-
Run
kubectl get pods -n kong
. Ensure that the control plane is running as expected.NAME READY STATUS kong-cp-kong-7bb77dfdf9-x28xf 1/1 Running
Data Plane
The Kong Gateway data plane is responsible for processing incoming traffic. It receives the routing configuration from the control plane using the clustering endpoint.
-
Create a
values-dp.yaml
file. -
Run
helm install
to create the release.helm install kong-dp kong/kong -n kong --values ./values-dp.yaml
-
Run
kubectl get pods -n kong
. Ensure that the data plane is running as expected.NAME READY STATUS kong-dp-kong-5dbcd9f6b9-f2w49 1/1 Running
Testing
Kong Gateway is now running. To send some test traffic, try the following:
-
Fetch the
LoadBalancer
address for thekong-dp
service and store it in thePROXY_IP
environment variablePROXY_IP=$(kubectl get service --namespace kong kong-dp-kong-proxy -o jsonpath='{range .status.loadBalancer.ingress[0]}{@.ip}{@.hostname}{end}')
-
Make a HTTP request to your
$PROXY_IP
. This will return aHTTP 404
served by Kong Gatewaycurl $PROXY_IP/mock/anything
-
In another terminal, run
kubectl port-forward
to set up port forwarding and access the admin API.kubectl port-forward -n kong service/kong-cp-kong-admin 8001
-
Create a mock service and route
curl localhost:8001/services -d name=mock -d url="https://httpbin.konghq.com" curl localhost:8001/services/mock/routes -d "paths=/mock"
-
Make a HTTP request to your
$PROXY_IP
again. This time Kong Gateway will route the request to httpbin.curl $PROXY_IP/mock/anything