5.1. Ingress

In this lab, you install the Ingress controller Traefik and make the message board from 4.2 reachable by a host name.

Step 1: Install Traefik

Create the directories of this lab and change into it:

mkdir -p ~/labs/5.1/traefik
cd ~/labs/5.1

Create the file values.yaml with the settings for Traefik in ~/labs/5.1/traefik, a directory of its own, because the Clean Up deletes all manifests in ~/labs/5.1 at once:

service:
  spec:
    type: NodePort
ports:
  web:
    nodePort: 31337
  websecure:
    expose:
      default: false

Install the chart as the release traefik into the new namespace traefik:

helm install traefik oci://ghcr.io/traefik/helm/traefik --version 41.7.1 \
  -n traefik --create-namespace -f traefik/values.yaml
Pulled: ghcr.io/traefik/helm/traefik:41.7.1
Digest: sha256:ce4608f8ad8fff14b6e335f525b1f430798c91c0b74fe0751d8e3f00c97671f0
NAME: traefik
LAST DEPLOYED: Tue Oct 13 17:00:37 2026
NAMESPACE: traefik
STATUS: deployed
REVISION: 1
DESCRIPTION: Install complete
TEST SUITE: None
NOTES:
traefik with docker.io/traefik:v3.7.14 has been deployed successfully on traefik namespace!

Wait about 10 seconds and list the Pod and the Service:

kubectl get pods -n traefik
NAME                      READY   STATUS    RESTARTS   AGE
traefik-d6b4b748b-k9fs4   1/1     Running   0          10s

If the Pod isn’t 1/1 yet, wait a moment and repeat the command.

kubectl get services -n traefik
NAME      TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
traefik   NodePort   10.43.248.200   <none>        80:31337/TCP   10s

Send a request to Traefik:

curl http://localhost:31337
404 page not found

Explanation

Traefik is an Ingress controller: a reverse proxy that runs as a Pod and forwards each request according to the rules of the Ingress resources in the cluster.

By default, the chart creates a LoadBalancer Service, which would stay <pending> in your cluster. The values turn it into a NodePort Service on port 31337, which 2.1 made reachable from your machine. They also leave out the HTTPS port websecure, because the labs use plain HTTP.

The 404 comes from Traefik itself: it received the request, but there’s no rule yet that tells it where to forward it.


Step 2: Expose the Message Board

Create the file messages-ingress.yaml in ~/labs/5.1 with a rule for the host name messages.localhost:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: messages
  namespace: messages-dev
spec:
  rules:
    - host: messages.localhost
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend
                port:
                  number: 80

Apply it and list the Ingresses in the namespace of the message board:

kubectl apply -f messages-ingress.yaml
ingress.networking.k8s.io/messages created
kubectl get ingress -n messages-dev
NAME       CLASS     HOSTS                ADDRESS   PORTS   AGE
messages   traefik   messages.localhost             80      0s
Names ending in .localhost

Chrome, Edge, Firefox and curl send every name ending in .localhost to your own machine, without a DNS entry (curl in WSL needs the entry below). If your browser can’t find the address, open it in one of them.

WSL: add the names to /etc/hosts

In WSL, curl may ask the DNS server of Windows for these names, which doesn’t know them, and fails with Could not resolve host. Add the names of this lab to /etc/hosts once:

echo "127.0.0.1 messages.localhost other.localhost whoami.localhost gateway.localhost" | sudo tee -a /etc/hosts

WSL rewrites /etc/hosts when it restarts. If the names stop working after a restart, run the command again.

Open http://messages.localhost:31337 in your browser. The message board shows the message from 4.2. Post another one, e.g. Hello Ingress, then read the messages through the Ingress:

curl http://messages.localhost:31337/api/messages
[{"id":2,"created_at":"2026-10-13T17:00:48.585984+00:00","text":"Hello Ingress"},{"id":1,"created_at":"2026-10-13T16:45:00.858198+00:00","text":"Hello Helm"}]

Explanation

The Ingress has one rule: requests for the host messages.localhost with a path that starts with / (so every path) go to port 80 of the Service frontend. The frontend still forwards /api/ to the backend, as in 3.1.

ColumnMeaning
CLASSThe Ingress controller in charge. The chart made Traefik the default, so the manifest doesn’t name it
HOSTSThe host names the rules match
ADDRESSStays empty in your cluster: there’s no load balancer that could provide an address

namespace: messages-dev in the metadata puts the Ingress next to the frontend, because an Ingress forwards only to Services in its own namespace. Traefik reads Ingresses from every namespace, and the NodePort 30088 of the frontend keeps working as well.


Step 3: Route by Path

Replace the content of messages-ingress.yaml with a second path: requests for /health go straight to the backend.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: messages
  namespace: messages-dev
spec:
  rules:
    - host: messages.localhost
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend
                port:
                  number: 80
          - path: /health
            pathType: Prefix
            backend:
              service:
                name: backend
                port:
                  number: 8000

Apply the change:

kubectl apply -f messages-ingress.yaml
ingress.networking.k8s.io/messages configured

Call /health three times. echo adds the line break that the answer lacks:

for i in 1 2 3; do curl -s http://messages.localhost:31337/health; echo; done
{"status":"ok","pod":"backend-59d46555fc-nf4jk"}
{"status":"ok","pod":"backend-59d46555fc-k8jtz"}
{"status":"ok","pod":"backend-59d46555fc-p4m88"}

If you get the 404 Not Found page of nginx instead, Traefik hasn’t picked up the new path yet. Wait a moment and repeat the command.

Send a request for a host without a rule:

curl http://other.localhost:31337
404 page not found

Explanation

Both paths belong to the same host, and both match /health: / matches every path. When several rules match, Traefik takes the longest one, so /health goes to the backend and every other path to the frontend. Before this step, /health went to the frontend, and nginx didn’t know it.

Traefik spreads the requests over the three backend Pods, so the answers come from different Pods. A host without a rule gets the 404 from Step 1. One Ingress controller on one port can serve any number of applications and tells them apart by host name and path.


Optional Tasks

Finished early? Try these tasks. The following labs don’t depend on them. Each task lists the commands you need. Open the solution if you get stuck.

Task 1: Who Am I

Run the image traefik/whoami:v1.12.0 from 2.6 with a Deployment and a Service on port 80 in the namespace default. Make it reachable at http://whoami.localhost:31337 with an Ingress, then list the Ingresses of all namespaces.

CommandEffect
kubectl get <type> -ALists the resources of all namespaces
Solution

Create the file whoami.yaml in ~/labs/5.1:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: whoami
spec:
  replicas: 1
  selector:
    matchLabels:
      app: whoami
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
        - name: whoami
          image: traefik/whoami:v1.12.0
---
apiVersion: v1
kind: Service
metadata:
  name: whoami
spec:
  selector:
    app: whoami
  ports:
    - port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: whoami
spec:
  rules:
    - host: whoami.localhost
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: whoami
                port:
                  number: 80

Apply it and send a request:

kubectl apply -f ~/labs/5.1/whoami.yaml
deployment.apps/whoami created
service/whoami created
ingress.networking.k8s.io/whoami created
curl http://whoami.localhost:31337
Hostname: whoami-6469954fc-5hqgk
IP: 127.0.0.1
IP: ::1
IP: 10.42.2.44
IP: fe80::4087:fbff:fe91:e576
RemoteAddr: 10.42.2.43:37460
GET / HTTP/1.1
Host: whoami.localhost:31337
User-Agent: curl/8.18.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 10.42.2.1
X-Forwarded-Host: whoami.localhost:31337
X-Forwarded-Port: 31337
X-Forwarded-Proto: http
X-Forwarded-Server: traefik-d6b4b748b-k9fs4
X-Real-Ip: 10.42.2.1

If you get 404 page not found, wait a few seconds and repeat the command.

kubectl get ingress -A
NAMESPACE      NAME       CLASS     HOSTS                ADDRESS   PORTS   AGE
default        whoami     traefik   whoami.localhost               80      3s
messages-dev   messages   traefik   messages.localhost             80      27s

Two applications in two namespaces share the port 31337. Traefik tells them apart by the host name. whoami shows the request as it arrived: Host is the name Traefik routed by, X-Forwarded-Server the Traefik Pod that forwarded it.

Task 2: Control Room

Traefik shows its routes in a dashboard. Turn it on with the chart value ingressRoute.dashboard.enabled: true in a second values file dashboard.yaml in ~/labs/5.1/traefik. Open http://localhost:8080/dashboard/ through a port forward to port 8080 of the Deployment traefik and find the routes of your Ingress.

CommandEffect
helm upgrade <release> <chart> -f <file> -f <file>Upgrades with several values files (later files win)
kubectl port-forward -n <namespace> deployment/<name> <port>:<port>Forwards a local port to a Pod of the Deployment
Solution

Create dashboard.yaml in ~/labs/5.1/traefik:

ingressRoute:
  dashboard:
    enabled: true

Upgrade the release with both values files:

helm upgrade traefik oci://ghcr.io/traefik/helm/traefik --version 41.7.1 \
  -n traefik -f ~/labs/5.1/traefik/values.yaml -f ~/labs/5.1/traefik/dashboard.yaml
Pulled: ghcr.io/traefik/helm/traefik:41.7.1
...
Release "traefik" has been upgraded. Happy Helming!
NAME: traefik
...
REVISION: 2
...

Forward the port 8080 of the Traefik Pod to your machine:

kubectl port-forward -n traefik deployment/traefik 8080:8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

Open http://localhost:8080/dashboard/ in your browser. Under HTTP Routers, you find the two rules of your Ingress, e.g. Host("messages.localhost") && PathPrefix("/health") with the service messages-dev-backend-8000. Every rule appears a second time with the prefix websecure-, for the HTTPS port that you left out. Stop the port forward with Ctrl+C.

The dashboard shows what Traefik made of your Ingress: a router per rule, and a service per Service and port. Pass values.yaml again with every upgrade: as soon as you pass a values file, helm upgrade starts from the defaults of the chart. Without it, Traefik would get a LoadBalancer Service again.

Task 3: The Successor

The Gateway API is the successor of Ingress. Make the message board reachable at http://gateway.localhost:31337 with an HTTPRoute in the namespace messages-dev that attaches to the Gateway traefik-gateway in the namespace traefik.

The resource types of the Gateway API aren’t part of Kubernetes. Install them from https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml. Then let the chart create the Gateway with a third values file gateway.yaml in ~/labs/5.1/traefik:

providers:
  kubernetesGateway:
    enabled: true
gateway:
  listeners:
    web:
      namespacePolicy:
        from: All
CommandEffect
kubectl apply --server-side -f <url>Applies the manifests at the URL (--server-side is needed for very large resources)
kubectl get gateway -n <namespace>Lists the Gateways. PROGRAMMED True means the controller has set it up
kubectl get httproute -n <namespace>Lists the HTTPRoutes
Solution

Install the resource types of the Gateway API:

kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml
customresourcedefinition.apiextensions.k8s.io/backendtlspolicies.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/gatewayclasses.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/gateways.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/grpcroutes.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/httproutes.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/listenersets.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/referencegrants.gateway.networking.k8s.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/tlsroutes.gateway.networking.k8s.io serverside-applied
validatingadmissionpolicy.admissionregistration.k8s.io/safe-upgrades.gateway.networking.k8s.io serverside-applied
validatingadmissionpolicybinding.admissionregistration.k8s.io/safe-upgrades.gateway.networking.k8s.io serverside-applied

Upgrade Traefik with gateway.yaml:

helm upgrade traefik oci://ghcr.io/traefik/helm/traefik --version 41.7.1 \
  -n traefik -f ~/labs/5.1/traefik/values.yaml -f ~/labs/5.1/traefik/gateway.yaml
Pulled: ghcr.io/traefik/helm/traefik:41.7.1
...
Release "traefik" has been upgraded. Happy Helming!
...
⚠️ DEPRECATION WARNING: Gateway API CRDs will no longer be shipped with this chart in a future major version.
You will need to install them yourself before deploying Traefik v3.7:
  kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml

The warning names the resource types you already installed. Check the Gateway:

kubectl get gateway -n traefik
NAME              CLASS     ADDRESS   PROGRAMMED   AGE
traefik-gateway   traefik             True         15s

If PROGRAMMED isn’t True yet, wait a moment and repeat the command. Create the file messages-route.yaml in ~/labs/5.1:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: messages
  namespace: messages-dev
spec:
  parentRefs:
    - name: traefik-gateway
      namespace: traefik
  hostnames:
    - gateway.localhost
  rules:
    - backendRefs:
        - name: frontend
          port: 80

Apply it and read the messages through the Gateway:

kubectl apply -f ~/labs/5.1/messages-route.yaml
httproute.gateway.networking.k8s.io/messages created
kubectl get httproute -n messages-dev
NAME       HOSTNAMES               AGE
messages   ["gateway.localhost"]   1s
curl http://gateway.localhost:31337/api/messages
[{"id":2,"created_at":"2026-10-13T17:00:48.585984+00:00","text":"Hello Ingress"},{"id":1,"created_at":"2026-10-13T16:45:00.858198+00:00","text":"Hello Helm"}]

If you get 404 page not found, wait a few seconds and repeat the command.

An Ingress describes everything in one resource. The Gateway API splits it in two: the Gateway is the entry point, created by the chart in the namespace traefik and usually owned by the team that runs the cluster. The HTTPRoute belongs to the application, lives in its namespace and attaches to the Gateway with parentRefs. By default, a Gateway accepts routes only from its own namespace. namespacePolicy.from: All opens it to every namespace.


Clean Up

Delete the Ingress and everything the optional tasks created from the files in ~/labs/5.1:

kubectl delete -f ~/labs/5.1/
ingress.networking.k8s.io "messages" deleted from messages-dev namespace
httproute.gateway.networking.k8s.io "messages" deleted from messages-dev namespace
deployment.apps "whoami" deleted from default namespace
service "whoami" deleted from default namespace
ingress.networking.k8s.io "whoami" deleted from default namespace

The lines for the HTTPRoute and whoami appear only if you did Task 1 or 3. If you did Task 2 or 3, reset Traefik to the values from Step 1:

helm upgrade traefik oci://ghcr.io/traefik/helm/traefik --version 41.7.1 \
  -n traefik -f ~/labs/5.1/traefik/values.yaml
Pulled: ghcr.io/traefik/helm/traefik:41.7.1
...
Release "traefik" has been upgraded. Happy Helming!
...

If you did Task 3, delete the resource types of the Gateway API as well:

kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml
customresourcedefinition.apiextensions.k8s.io "backendtlspolicies.gateway.networking.k8s.io" deleted
...
validatingadmissionpolicybinding.admissionregistration.k8s.io "safe-upgrades.gateway.networking.k8s.io" deleted

Traefik and the releases from chapter 4 keep running, because the challenges in chapter 6 build on them.


Complete files

~/labs/5.1/traefik/values.yaml:

service:
  spec:
    type: NodePort
ports:
  web:
    nodePort: 31337
  websecure:
    expose:
      default: false

~/labs/5.1/messages-ingress.yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: messages
  namespace: messages-dev
spec:
  rules:
    - host: messages.localhost
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend
                port:
                  number: 80
          - path: /health
            pathType: Prefix
            backend:
              service:
                name: backend
                port:
                  number: 8000