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
Like a smart receptionist with a digital directory:
- Reads the Ingress rules (βmarketing β floor 3β)
- Physically routes visitors to the right office
- Updates routing in real-time when rules change
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!