Kubernetes Field Guide · Chapter 8 of 16
Ingress and Gateway API: getting traffic into the cluster
You want many apps behind one address, routed by hostname and path, with HTTPS. That is an Ingress, or its successor, the Gateway API. Learn how routing rules match, how certificates get issued automatically, and how to avoid paying for a load balancer per app.
- 35 min
- Intermediate
- Hands-on
- Free
By Joshua Sequeira, founding engineer running Kubernetes in production. Updated .
By the end you can
0 of 5
Live lab in this chapter
A real-feeling terminal and a live cluster map, right in your browser. Every command block below has a ▶ Run in lab button.
Why one entry point
Last chapter ended with a cost problem: every LoadBalancer Service is its own cloud load balancer. An Ingress puts one HTTP-aware entry point in front of many ClusterIP Services:
- One load balancer and one public IP for every app.
- Routing by hostname (
shop.example.com) and path (/api). - HTTPS handled in one place, with certificates issued and renewed automatically.
On a managed cloud cluster, the first point alone pays for the lesson. Slide to the number of public services you run:
Interactive · Cost
A load balancer per Service, or one Ingress?
Step through it
One public request, from the internet to a pod
- Browsershop.example.com/cart
- Load balancerone per cluster
- Ingress controllerTraefik, NGINX, Envoy
- ServiceClusterIP: shop
- Podshop
Step 0 of 5
Press Play, or step through with Next.
Ingress controllers
An Ingress object is only configuration. An Ingress controller, a reverse proxy running in the cluster, watches Ingress objects and routes traffic. Nothing works until you install one, and ingressClassName says which controller should handle each Ingress.
| Controller | Notes |
|---|---|
| Traefik | Ships with K3s. Supports Ingress and Gateway API. Used in this chapter. |
| NGINX-based controllers | The community ingress-nginx project was retired in March 2026. Existing installs keep working but get no fixes; plan a move to a maintained controller or the Gateway API. |
| Envoy-based (Envoy Gateway, Contour, Istio) | Strong Gateway API support, good for advanced traffic management. |
| Cloud controllers (AWS Load Balancer Controller, GKE) | Program the cloud's own load balancer. On AWS, each Ingress becomes its own ALB unless you group them with the group.name annotation. |
Host and path routing
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: shop
annotations:
cert-manager.io/cluster-issuer: letsencrypt
spec:
ingressClassName: traefik
tls:
- hosts: [shop.example.com]
secretName: shop-tls
rules:
- host: shop.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api
port:
number: 8080
- path: /
pathType: Prefix
backend:
service:
name: storefront
port:
number: 80- Which controller handles this Ingress.
- Serve HTTPS for these hosts with the certificate stored in shop-tls.
- Matches whole path segments: /api matches /api and /api/orders, not /apix. Exact matches only the exact path.
- A normal ClusterIP Service from the last chapter.
Try requests against those rules:
Interactive
Which backend gets this request?
| Host | Path | Type | Backend |
|---|---|---|---|
| shop.example.com | /api | Prefix | api:8080 |
| shop.example.com | / | Prefix | storefront:80 |
| blog.example.com | / | Prefix | blog:80 |
TLS with cert-manager
cert-manager turns certificates into something you never think about. Define an issuer once; then any Ingress with the annotation gets a Let's Encrypt certificate, stored as a Secret and renewed well before it expires.
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: you@example.com
privateKeySecretRef:
name: letsencrypt-account
solvers:
- http01:
ingress:
ingressClassName: traefik- Let's Encrypt production. While testing, use the staging URL: production has strict rate limits.
- Proves you own the domain by answering a challenge over HTTP through the same controller. DNS must already point at your load balancer.
Gateway API: what comes after Ingress
Ingress is stable but frozen, and anything beyond basic routing lives in controller-specific annotations. The Gateway API is its successor, split by who owns what:
- GatewayClass: which implementation (set by whoever installs the controller).
- Gateway: the listeners, ports and certificates (the platform team).
- HTTPRoute: routing for one app (the app team, in their own namespace).
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: storefront
spec:
parentRefs:
- name: public
namespace: infra
hostnames: [shop.example.com]
rules:
- backendRefs:
- name: storefront-v1
port: 80
weight: 90
- name: storefront-v2
port: 80
weight: 10- Attaches this route to a shared Gateway owned by another team.
- A canary: one request in ten goes to v2. Change the weights to shift traffic.
For a new cluster, start with Gateway API if your controller supports it well. Ingress remains fine for simple host and path routing.
Hands-on: route two apps through one entry point
The lab is docked at the bottom of your screen.
Live lab · no install
Route two apps through one entry point
- Tasks0/7
Install an Ingress controller
An Ingress is only rules. Traefik is the program that reads them and routes traffic.
helm repo add traefik https://traefik.github.io/charts helm install traefik traefik/traefik -n traefik --create-namespace kubectl -n traefik rollout status deploy/traefikRun two apps that answer with their name
kubectl create deployment shop --image=hashicorp/http-echo:1.0.0 -- /http-echo -text=shop kubectl create deployment blog --image=hashicorp/http-echo:1.0.0 -- /http-echo -text=blog kubectl expose deployment shop --port=80 --target-port=5678 kubectl expose deployment blog --port=80 --target-port=5678Apply the routing rules
lab-ingress.yaml routes by host name. Open it in the Files tab.
kubectl apply -f lab-ingress.yaml kubectl get ingressOpen a tunnel to Traefik
kind has no cloud load balancer, so port-forward stands in for one.
kubectl -n traefik port-forward svc/traefik 8080:80 &Send requests for two different hosts
Same address, different Host header, different app.
curl -H "Host: shop.example.com" localhost:8080 curl -H "Host: blog.example.com" localhost:8080Ask for a host with no rule
curl -i -H "Host: other.example.com" localhost:8080Add path routing: /blog on the shop host
Edit lab-ingress.yaml in the Files tab: add a /blog path under shop.example.com that goes to the blog Service. Then apply and test.
edit lab-ingress.yaml- Lab complete. Keep experimenting, or press Reset to start again.
- ready
- starting / not ready
- failing
- terminating
Prefer your own machine? The same steps on a local cluster
Install Helm (chapter 12 explains it properly) and Traefik:
brew install helm
helm repo add traefik https://traefik.github.io/charts
helm install traefik traefik/traefik -n traefik --create-namespace
kubectl -n traefik rollout status deploy/traefik
helm install- Installs the Traefik controller and an IngressClass named traefik.
LoadBalancer pending- kind has no cloud, so the Service stays pending. You will use port-forward instead.
Two tiny apps that answer with their name:
kubectl create deployment shop --image=hashicorp/http-echo:1.0.0 -- /http-echo -text=shop
kubectl create deployment blog --image=hashicorp/http-echo:1.0.0 -- /http-echo -text=blog
kubectl expose deployment shop --port=80 --target-port=5678
kubectl expose deployment blog --port=80 --target-port=5678
Save the routing rules as lab-ingress.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: lab
spec:
ingressClassName: traefik
rules:
- host: shop.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: shop
port:
number: 80
- host: blog.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: blog
port:
number: 80kubectl apply -f lab-ingress.yaml
kubectl -n traefik port-forward svc/traefik 8080:80 &
curl -H "Host: shop.example.com" localhost:8080
curl -H "Host: blog.example.com" localhost:8080
curl -i -H "Host: other.example.com" localhost:8080
shop
blog
HTTP/1.1 404 Not Found-H "Host: ..."- Pretends the request was for that domain, so you do not need DNS.
404- No rule for that host: Traefik answers itself.
Mini mission
Add path routing
Make shop.example.com/blog serve the blog app while everything else on shop.example.com still goes to shop.
Reveal one safe solution
Add a second path to the shop rule, above or below / (order does not matter, the longest prefix wins):
- path: /blog
pathType: Prefix
backend:
service:
name: blog
port:
number: 80kubectl apply -f lab-ingress.yaml
curl -H "Host: shop.example.com" localhost:8080/blog
curl -H "Host: shop.example.com" localhost:8080/cart
The first prints blog, the second shop. Stop the port-forward with kill %1.
Check yourself
Quiz
0 of 4 answered