Ingress โ HTTP Routing
An Ingress exposes HTTP and HTTPS routes from outside the cluster to Services within the cluster. It provides URL-based routing, SSL termination, and name-based virtual hosting.
Think of Ingress as a smart entry point that routes traffic to the right Service based on the URL.
Ingress Architecture
Internet
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Load Balancer (single IP) โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Ingress Controller (NGINX, Traefik) โ
โ โ
โ /api/* โโโโโโโถ Service: api-svc โ
โ /web/* โโโโโโโถ Service: web-svc โ
โ blog.example.com โโโถ Service: blog-svc โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
One entry point, multiple Services
Creating an Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: myapp.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
ingressClassName โ Which Ingress controller handles this rule (NGINX, Traefik, etc.).
rules โ Define hostnames and path-based routing.
pathType: Prefix โ Matches paths that start with the specified value.
SSL/TLS Termination
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tls-ingress
spec:
ingressClassName: nginx
tls:
- hosts:
- myapp.example.com
secretName: myapp-tls-secret
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 443
The tls section points to a Kubernetes Secret containing your TLS certificate and key. The Ingress controller handles HTTPS on the outside and forwards plain HTTP to your services.
Installing an Ingress Controller
Ingress resources do nothing without an Ingress controller. You must install one:
# Install NGINX Ingress Controller with Helm
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install nginx-ingress ingress-nginx/ingress-nginx
# Check if the controller is running
kubectl get pods -n ingress-nginx