Skip to Content

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 , founding engineer running Kubernetes in production. Updated .

usersLBone IPIngress controllerTraefik or nginxTLS ends hereshop.example.comexample.com/apihost: shop.example.compath: /apisvc shopsvc apishopapishopapi
The chapter in one pictureOne entry point with TLS, routing each host and path to the right Service.

By the end you can

0 of 5

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?

Service type LoadBalancer for each

One Ingress, one load balancer

AWS us-east-1 list prices, November 2026: $0.0225 per load balancer hour plus $0.005 per public IPv4 address hour, one address per zone. Traffic charges (LCUs) come on top in both designs, and other clouds and regions differ. The Ingress controller's own pods run on nodes you already pay for.

Step through it

One public request, from the internet to a pod

  1. Browsershop.example.com/cart
  2. Load balancerone per cluster
  3. Ingress controllerTraefik, NGINX, Envoy
  4. ServiceClusterIP: shop
  5. 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.

ControllerNotes
TraefikShips with K3s. Supports Ingress and Gateway API. Used in this chapter.
NGINX-based controllersThe 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

ingress.yaml
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?

HostPathTypeBackend
shop.example.com/apiPrefixapi:8080
shop.example.com/Prefixstorefront:80
blog.example.com/Prefixblog:80

The longest matching Prefix path wins. A host with no rule gets the default backend.

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.

clusterissuer.yaml
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).
httproute.yaml
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

Live lab · no install

Route two apps through one entry point

kind-learn
  1. Tasks0/7
  2. 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/traefik
  3. Run 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=5678
  4. Apply the routing rules

    lab-ingress.yaml routes by host name. Open it in the Files tab.

    kubectl apply -f lab-ingress.yaml
    kubectl get ingress
  5. Open 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 &
  6. 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:8080
  7. Ask for a host with no rule
    curl -i -H "Host: other.example.com" localhost:8080
  8. Add 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
  9. Lab complete. Keep experimenting, or press Reset to start again.
↑↓ history · Tab complete · Ctrl+C stop
Cluster map live
  • 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:

Terminal
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:

Terminal
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:

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: 80
Terminal
kubectl 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):

lab-ingress.yaml (shop rule)
- path: /blog
            pathType: Prefix
            backend:
              service:
                name: blog
                port:
                  number: 80
Terminal
kubectl 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

  1. 1. You apply an Ingress and nothing happens. The most likely reason?
  2. 2. Rules: /api → api, / → storefront, both Prefix. Where does /api/orders go?
  3. 3. What does cert-manager do?
  4. 4. What can an HTTPRoute do that a plain Ingress cannot do portably?

Further reading