🎯 What It Is

An Ingress Controller is a Pod (or set of Pods) that watches Ingress resources and configures a load balancer (like Traefik, Nginx, or HAProxy) to route traffic accordingly.

βœ… Ingress = configuration

πŸ”Œ Ingress Controller = the engine that enforces it

πŸ’‘ Real-World Analogy

Like a smart receptionist with a digital directory:


πŸ§ͺ Example: Use k3s’s Built-in Traefik Controller

Good news! βœ… k3s includes Traefik by default β€” no extra install needed!

Step 1: Deploy Two Sample Apps

# web.yaml
apiVersion: apps/v1
kind: Deployment
meta
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    meta
      labels:
        app: web
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
meta
  name: web
spec:
  selector:
    app: web
  ports:
  - port: 80

# api.yaml
apiVersion: apps/v1
kind: Deployment
meta
  name: api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api
  template:
    meta
      labels:
        app: api
    spec:
      containers:
      - name: httpd
        image: httpd
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
meta
  name: api
spec:
  selector:
    app: api
  ports:
  - port: 80

Apply:

kubectl apply -f web.yaml -f api.yaml

Step 2: Create an Ingress (as in Topic 1)

# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
meta
  name: main-ingress
spec:
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web
            port:
              number: 80
  - host: api.example.com
    http:
      paths:
      - path: /v1
        pathType: Prefix
        backend:
          service:
            name: api
            port:
              number: 80

Apply:

kubectl apply -f ingress.yaml

Step 3: Get the Ingress IP and Test

# Get Traefik's LoadBalancer IP (in k3s, it's the node IP)
kubectl get svc -n kube-system | grep traefik
# NAME      TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)
# traefik   LoadBalancer   10.43.123.45    192.168.1.100   80:32456/TCP

# Test with curl (simulate DNS via Host header)
curl -H "Host: web.example.com" <http://192.168.1.100>
# βœ… Returns nginx welcome page

curl -H "Host: api.example.com" <http://192.168.1.100/v1>
# βœ… Returns Apache welcome page

βœ… Result: Traefik automatically configured itself based on your Ingress!