Feb 19, 2025
Kong API Gateway + Kubernetes: Ingress, Auth & Rate Limiting
Video Summary
In this tutorial, we will deploy the Kong API Gateway on a Kubernetes cluster using Helm, configure a Kong Ingress Controller for external routing to a sample "Grade Submission API," implement key-based authentication for securing the API, and finally set up rate-limiting to control incoming requests.
The end goal is to ensure that:
The Grade Submission API is exposed externally via Kong.
Only valid API key holders can access the API (Key-Auth plugin).
We limit how many requests each consumer can make within a fixed time window (Rate-Limiting plugin).
Prerequisites
A functioning Kubernetes cluster.
If you are running locally, solutions like Docker Desktop or minikube work well.
The kubectl CLI installed and configured to talk to your cluster.
Helm installed on your local machine.
Basic knowledge of Kubernetes objects (Deployment, Service, Ingress, etc.).
What We’ll Build
We have a stateless Grade Submission API running in our cluster. We want to expose it to external clients, secure it with API key authentication, and limit how many requests each consumer can make in one minute.
Specifically, Kong will serve as:
Ingress Controller / API Gateway – forwards external traffic to the correct internal service.
Security Layer – only authorized calls (with valid API key) can pass.
Traffic Control – limit request volume from each consumer to prevent abuse or DDoS.
Video Chapters Overview
Below are the key time-stamped sections from the video:
00:00:00 – 00:01:06: What to Expect: Kong API Gateway on Kubernetes
00:01:06 – 00:02:14: Download and Test Starter Code
00:02:14 – 00:04:07: Test Base Application Before Kong
00:04:07 – 00:13:34: Installing Kong Gateway Using Helm on Kubernetes Cluster
00:13:34 – 00:21:23: Kong Ingress Controller: Configuring API Routes
00:21:23 – 00:30:30: Securing APIs: Kong Key Authentication Plugin Setup
00:30:30 – end: Kong Rate Limiting Plugin: Traffic Control Implementation
Starter Code and Basic Setup
All starter YAML manifests for the Grade Submission API are available in the GitHub repository. Here is the key portion that deploys our simple API:
Applying the Starter Manifests
Save the file as starter-manifests.yaml
(or use the provided one in the repository) and run:
Check that everything is up and running:
Testing the Base Application
If you want to test the Grade Submission API before integrating Kong, do a port-forward:
Open a new terminal and test:
This confirms our API is working. Next, we’ll install Kong and expose this service to external traffic without manual port-forwarding.
Installing Kong Gateway Using Helm
Kong provides an official Helm chart that bundles all configurations for Kong Gateway (including the Ingress Controller).
Adding the Kong Helm Repository
Search to confirm you see the Kong chart:
Deploying Kong with helm install
Install the chart into a new namespace called kong
:
Note: Check the Kong Helm Repository for the latest chart version or maintain the version in the tutorial (2.47.0) for consistency.
Run:
You should see pods for both the proxy
and ingress-controller
.
Configuring NodePort vs. LoadBalancer
If you run Kubernetes on a local environment (Docker Desktop or minikube), the default Service
type might be set to LoadBalancer
. On most local setups, you need a NodePort
instead because you don’t have a cloud load balancer available.
If necessary, modify values.yaml
with:
This ensures Kong’s proxy service is exposed on a NodePort (e.g., 30000+
).
If you’re on a cloud provider (AWS, GCP, Azure), you can leave it as LoadBalancer
so that a standard cloud load balancer is automatically provisioned.
Configuring the Kong Ingress Controller
Ingress Resource for Routing
Now, let’s define an Ingress
resource to route traffic from Kong to our grade-submission-api
Service. Below is an example YAML (call it kong-ingress.yaml
):
Apply it:
Check the route:
Look for kong-proxy
or similar. If it shows type NodePort
, note the assigned node port (e.g., 30664
). Now test:
You should see either an empty array or “cannot GET” (depending on your app logic). If the logs show requests are hitting your service, you have successfully routed traffic through Kong.
Strip Path Explanation
konghq.com/strip-path: "false"
preserves the exact path (/grades
) when forwarding requests to the backend service.If set to
"true"
, it would strip/grades
and send requests to the backend as/
.
Securing the API with Key-Auth Plugin
We don’t want our API open to the world. Let’s enforce an API key requirement.
Creating the Kong Plugin Resource
Define a custom resource of kind KongPlugin
. Create a file (e.g., kong-auth-plugin.yaml
):
This plugin says: “Any request must have a header apikey: <VALID_KEY>
to be allowed through.”
Defining a Kong Consumer
We create a Consumer that will represent a client/application allowed to make requests. It references credentials (stored in a Secret). For example (kong-consumer.yaml
):
Here, we reference a secret named user1-api-key
.
Storing the API Key in a Secret
Finally, define the Secret which stores the actual key (kong-secret.yaml
):
key: your-secret-key
is the actual token the consumer must include as a header.kongCredType
must be set tokey-auth
to match the plugin type.
Linking the Plugin with the Ingress
In the Ingress
definition (from kong-ingress.yaml
), add a reference to this plugin:
Re-apply all resources:
Now, if you attempt to call GET /grades
without the correct header, you should see:
When including the correct key:
You should succeed!
Applying Rate Limiting
Next, let’s prevent any single consumer from overwhelming our API by limiting requests per minute.
Configuring the Rate-Limiting Plugin
Create another KongPlugin
resource (e.g., kong-rate-limit.yaml
):
Add that plugin to your Ingress annotations:
Re-apply:
Testing Rate Limit Enforcement
Make repeated calls:
You should see HTTP 429
“API rate limit exceeded” on the 6th attempt. The plugin effectively throttles traffic from that specific consumer.
Final Testing
Once everything is in place, you can:
Verify the pod and service are all running:
Confirm you cannot call the API without an API key or if you exceed the rate limit.
Successfully call the API with a valid key and under the allowed threshold.
Useful Resources
GitHub Repository (Full Code):
https://github.com/rslim087a/kong-api-gateway-kubernetes-tutorial
Installing Helm (Mac/Windows):
https://kubernetestraining.io/blog/installing-helm-on-mac-and-windows
Kong Helm Charts:
Kubernetes Full Course:
Conclusion
By following these steps, you have:
Deployed a simple microservice (Grade Submission API) on Kubernetes.
Installed Kong via Helm, which acts as both an Ingress Controller and an API Gateway.
Configured routing rules to expose your internal service through Kong.
Implemented the Key Authentication plugin to restrict access to valid API key holders.
Added rate limiting to throttle traffic and prevent potential DDoS or abuse.
This setup demonstrates how Kong can serve as a robust API management platform—handling ingress traffic, authentication, and traffic policies all within your Kubernetes cluster.
Kubernetes Training
If you find these guides helpful, check out our Kubernetes Training course