Skip to content
Hands-on IT IT Drills

Day 8: Ingress and Gateway API

Goal: You route HTTP and HTTPS traffic to Services by hostname, path, header and weight – with Ingress and with the Gateway API. · Duration: approx. 60 min · Prerequisite: Day 7

Briefing

CKA: “Know how to use Ingress controllers and Ingress resources” and “Use the Gateway API to manage Ingress traffic” (part of the 20 %).

Ingress Gateway API
Objects Ingress GatewayClass, Gateway, HTTPRoute
Roles one resource for everything operators: Gateway, teams: routes
Capabilities host, path, TLS plus headers, weights, redirects

Both need a controller. We use Traefik: it can do both. ingress-nginx has not been maintained since March 2026.

mkdir -p ~/cka/tag08 && cd ~/cka/tag08
k create ns tag08
k config set-context --current --namespace=tag08

Drill 1: Helm and Gateway API CRDs

We install Traefik with Helm – you will learn Helm itself in more detail on Day 11.

cd /tmp
curl -sSLO https://get.helm.sh/helm-v4.3.2-linux-amd64.tar.gz
curl -sSL https://get.helm.sh/helm-v4.3.2-linux-amd64.tar.gz.sha256sum | sha256sum -c
tar xzf helm-v4.3.2-linux-amd64.tar.gz
sudo install -m 755 linux-amd64/helm /usr/local/bin/helm
helm version --short
cd ~/cka/tag08

Expected:

helm-v4.3.2-linux-amd64.tar.gz: OK
v4.3.2+g8346aaa

The Gateway API types are not part of Kubernetes; they are CRDs:

G=https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.7.0
k apply --server-side -f $G/standard-install.yaml

Expected (last lines, shortened):

customresourcedefinition.apiextensions.k8s.io/udproutes.gateway.networking.k8s.io
serverside-applied
...

Save your progress? Sign up for free

Drill 2: Install Traefik

helm repo add traefik https://traefik.github.io/charts
helm repo update
helm install traefik traefik/traefik --version 42.4.1 -n traefik --create-namespace \
  --set providers.kubernetesGateway.enabled=true --set gateway.enabled=false
k rollout status deployment traefik -n traefik
k get svc -n traefik
k get ingressclass,gatewayclass

Expected:

deployment "traefik" successfully rolled out
NAME      TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)
traefik   LoadBalancer   10.100.102.245   172.16.0.242   80:30579/TCP,443:30555/TCP
NAME                                               CONTROLLER                      ...
ingressclass.networking.k8s.io/traefik (default)   traefik.io/ingress-controller   ...

NAME                                             CONTROLLER                      ...
gatewayclass.gateway.networking.k8s.io/traefik   traefik.io/gateway-controller   ...

Traefik gets the IP 172.16.0.242 from MetalLB (Day 7). gateway.enabled=false prevents a prebuilt Gateway – you build that yourself in Drill 5.

Save your progress? Sign up for free

Drill 3: Two apps, one Ingress

for a in blue green; do
  k create deployment $a --image=registry.k8s.io/e2e-test-images/agnhost:2.53 \
    -- /agnhost netexec --http-port=8080
  k expose deployment $a --port=80 --target-port=8080
done
k create ingress shop --class=traefik --rule="blue.lab/*=blue:80" \
  --rule="green.lab/*=green:80"
k get ingress shop

Expected:

ingress.networking.k8s.io/shop created
NAME   CLASS     HOSTS                ADDRESS        PORTS   AGE
shop   traefik   blue.lab,green.lab   172.16.0.242   80      0s

Without a DNS entry, you test with the Host header:

curl -s -H 'Host: blue.lab' 172.16.0.242/hostname; echo
curl -s -H 'Host: green.lab' 172.16.0.242/hostname; echo
curl -s -o /dev/null -w '%{http_code}\n' -H 'Host: red.lab' 172.16.0.242/hostname

Expected:

blue-6cb7899f86-q2l94
green-988b9479c-h4prm
404

Look at the generated YAML – /* becomes pathType: Prefix:

k create ingress demo --class=traefik --rule="blue.lab/api*=blue:80" $do \
  | sed -n '/^spec:/,$p'

Expected (shortened):

spec:
  ingressClassName: traefik
  rules:
  - host: blue.lab
    http:
      paths:
      - backend:
          service:
            name: blue
            port:
              number: 80
        path: /api
        pathType: Prefix

Save your progress? Sign up for free

Drill 4: TLS on the Ingress

openssl req -x509 -newkey rsa:2048 -nodes -days 30 -keyout tls.key -out tls.crt \
  -subj "/CN=blue.lab" -addext "subjectAltName=DNS:blue.lab"
k create secret tls blue-tls --cert=tls.crt --key=tls.key
k create ingress blue-tls --class=traefik --rule="blue.lab/*=blue:80,tls=blue-tls"
curl -s --resolve blue.lab:443:172.16.0.242 --cacert tls.crt https://blue.lab/hostname
echo

Expected:

secret/blue-tls created
ingress.networking.k8s.io/blue-tls created
blue-6cb7899f86-q2l94

--resolve replaces the DNS entry, --cacert trusts your self-signed certificate. Clean up the Ingress objects:

k delete ingress shop blue-tls

Save your progress? Sign up for free

Drill 5: Gateway and HTTPRoute

cat <<'EOF' | k apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: shop-gw
spec:
  gatewayClassName: traefik
  listeners:
  - name: http
    protocol: HTTP
    port: 8000
    allowedRoutes:
      namespaces:
        from: Same
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: shop
spec:
  parentRefs:
  - name: shop-gw
  hostnames:
  - shop.lab
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: blue
      port: 80
EOF
k get gateway shop-gw
k get httproute shop
curl -s -H 'Host: shop.lab' 172.16.0.242/hostname; echo

Expected:

NAME      CLASS     ADDRESS        PROGRAMMED   AGE
shop-gw   traefik   172.16.0.242   True         6s
NAME   HOSTNAMES      AGE
shop   ["shop.lab"]   6s
blue-6cb7899f86-q2l94

Why port 8000 and not 80? With Traefik, the listener port must match a Traefik EntryPoint: web listens on 8000 inside the container, websecure on 8443. The Service maps 80 and 443 to them.

Save your progress? Sign up for free

Drill 6: What a wrong port does

cat <<'EOF' | k apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: wrong-gw
spec:
  gatewayClassName: traefik
  listeners:
  - name: http
    protocol: HTTP
    port: 80
EOF
k get gateway wrong-gw
k describe gateway wrong-gw | grep -m1 'Cannot find'

Expected:

NAME       CLASS     ADDRESS        PROGRAMMED   AGE
wrong-gw   traefik   172.16.0.242   False        5s
      Message:   Cannot find entryPoint for Gateway: no matching entryPoint for port 80
and protocol "HTTP"

PROGRAMMED False means: the controller has seen the Gateway but cannot implement it. The reason is always in the status.

k delete gateway wrong-gw

Save your progress? Sign up for free

Drill 7: Header routing and canary with weights

cat <<'EOF' | k apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: shop
spec:
  parentRefs:
  - name: shop-gw
  hostnames:
  - shop.lab
  rules:
  - matches:
    - headers:
      - name: x-version
        value: green
    backendRefs:
    - name: green
      port: 80
  - backendRefs:
    - name: blue
      port: 80
      weight: 80
    - name: green
      port: 80
      weight: 20
EOF
curl -s -H 'Host: shop.lab' -H 'x-version: green' 172.16.0.242/hostname; echo
for i in $(seq 1 50); do curl -s -H 'Host: shop.lab' 172.16.0.242/hostname; echo; done \
  | cut -d- -f1 | sort | uniq -c

Expected (numbers vary around 40/10):

green-988b9479c-h4prm
     40 blue
     10 green

With the header always green, without the header split 80/20 – a canary release without any extra tool.

Save your progress? Sign up for free

Exercise: Speed Drills

  1. Create an Ingress api that routes api.lab/v1 to the Service blue (port 80). Target time: 30 s
  2. Show which IngressClass is the default. Target time: 15 s
  3. Show the conditions (conditions) of the HTTPRoute shop. Target time: 30 s

Solution

k create ingress api --class=traefik --rule="api.lab/v1*=blue:80"
k get ingressclass
k get httproute shop -o jsonpath='{.status.parents[0].conditions[*].type}{"\n"}'

Expected (excerpt):

ingress.networking.k8s.io/api created
NAME                CONTROLLER                      PARAMETERS   AGE
traefik (default)   traefik.io/ingress-controller   <none>       26s
Accepted ResolvedRefs

Save your progress? Sign up for free

Checkpoint

k get gateway shop-gw \
  -o jsonpath='{.status.conditions[?(@.type=="Programmed")].status}{"\n"}'

Expected: True

curl -s -H 'Host: shop.lab' -H 'x-version: green' 172.16.0.242/hostname; echo

Expected: a Pod name starting with green-.

Challenge

shop.lab should only be reachable over HTTPS: HTTP requests are redirected to HTTPS with 301.

Hint: A second listener on port 8443 with TLS, attach the existing route only to that listener (sectionName), and a second route with the RequestRedirect filter on the HTTP listener.

Solution

openssl req -x509 -newkey rsa:2048 -nodes -days 30 -keyout shop.key -out shop.crt \
  -subj "/CN=shop.lab" -addext "subjectAltName=DNS:shop.lab"
k create secret tls shop-tls --cert=shop.crt --key=shop.key
k edit gateway shop-gw

Add under listeners:

  - name: https
    protocol: HTTPS
    port: 8443
    hostname: shop.lab
    tls:
      mode: Terminate
      certificateRefs:
      - name: shop-tls
    allowedRoutes:
      namespaces:
        from: Same

Bind the existing route to the HTTPS listener and create the redirect:

k patch httproute shop --type=json \
  -p='[{"op":"add","path":"/spec/parentRefs/0/sectionName","value":"https"}]'
cat <<'EOF' | k apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: shop-redirect
spec:
  parentRefs:
  - name: shop-gw
    sectionName: http
  hostnames:
  - shop.lab
  rules:
  - filters:
    - type: RequestRedirect
      requestRedirect:
        scheme: https
        statusCode: 301
EOF
curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' -H 'Host: shop.lab' \
  172.16.0.242/hostname
curl -s --resolve shop.lab:443:172.16.0.242 --cacert shop.crt https://shop.lab/hostname
echo

Expected:

301 https://shop.lab/hostname
blue-6cb7899f86-q2l94

Clean up (Traefik and the Gateway CRDs stay):

k config set-context --current --namespace=default
k delete ns tag08

Save your progress? Sign up for free

Exam Tip

  • Ingress: k create ingress … --rule="host/pfad*=service:port,tls=secret" saves you the complete YAML.
  • Gateway API: After creating, always read the status (Accepted, ResolvedRefs, Programmed). ResolvedRefs False usually means: wrong Service name or port.
  • The exam names the GatewayClass and listener port in the task – don’t guess.

Enterprise Note

  • Gateways belong to the platform team, HTTPRoutes to the app teams (allowedRoutes with from: Selector).
  • Certificates come from cert-manager, not from openssl by hand.
  • For migrating from ingress-nginx, ingress2gateway and the book “Gateway API hands-on” help.