Skip to content

Room 18

INGRESS CONTROLLERS


The Traffic Router

  • Ingress is the smart HTTP gateway - routing requests based on hostname and path.
  • Install an Ingress controller and route traffic to multiple backends.

📜 Mission Briefing

  1. Install the NGINX Ingress controller:
    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
    
  2. Wait for the ingress controller to be ready.
  3. Apply ingress.yaml - defines routing rules for two services.
  4. The Ingress routes /app1 to service-a and /app2 to service-b.
  5. Test with curl using the Host header.
  6. The service-a returns the password ingress77.

Key Commands
Command Purpose
kubectl get ingress List Ingress resources
kubectl describe ingress NAME Ingress rules
kubectl get pods -n ingress-nginx Ingress controller pods
kubectl get ingressclass Available Ingress classes

How Ingress Works
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: api-service
                port:
                  number: 80
          - path: /web
            pathType: Prefix
            backend:
              service:
                name: web-service
                port:
                  number: 80
    - host: admin.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: admin-service
                port:
                  number: 80
  tls:
    - hosts:
        - app.example.com
      secretName: app-tls
# Path types:
# Exact:  /foo matches ONLY /foo
# Prefix: /foo matches /foo, /foo/, /foo/bar

# Ingress controller is NOT built-in - you must install one:
# Popular: nginx, traefik, HAProxy, istio, envoy

# Install nginx ingress for Kind
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

# Wait for it to be ready
kubectl wait --namespace ingress-nginx \
  --for=condition=ready pod \
  --selector=app.kubernetes.io/component=controller \
  --timeout=90s

# Test with curl
curl -H "Host: app.example.com" http://localhost/api

Hints

Hint 1

Install the ingress controller and wait:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl wait -n ingress-nginx --for=condition=ready pod -l app.kubernetes.io/component=controller --timeout=120s

Hint 2

Apply the ingress and test:

kubectl apply -f ingress.yaml
curl localhost/app1

Hint 3

The password is ingress77.


🔓 Unlock Room 19

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_19/README             \
        -out ../room_19/README.txt        \
        -pass pass:PASSWORD
cat ../room_19/README.txt