What is an Ingress in Kubernetes and how does it differ from a LoadBalancer Service?
An Ingress defines HTTP and HTTPS routing rules by host and path, handled by an Ingress controller. One load balancer can serve many services, while a LoadBalancer Service creates one external load balancer per Service.
Explain it simply
A LoadBalancer Service is a separate gate with its own security guard for each building. An Ingress is one main gate with a receptionist who reads the visitor's slip and directs them: 'accounts, go to block A; library, go to block B'.
The Ingress object is only a set of rules, such as shop.example.in/api goes to the api Service and shop.example.in/ goes to web. Nothing happens until an Ingress controller, such as ingress-nginx, Traefik or a cloud controller, is running; it reads the rules and does the routing. Benefits: one public IP for many services, TLS termination in one place, host and path routing, and lower cloud cost than many load balancers. Limitation: classic Ingress handles HTTP/HTTPS only. The newer Gateway API is its more expressive successor.
Example
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: shop
spec:
ingressClassName: nginx
rules:
- host: shop.example.in
http:
paths:
- path: /api
pathType: Prefix
backend:
service: {name: api, port: {number: 80}}What to say in the interview
"An Ingress holds HTTP/HTTPS routing rules by host and path, implemented by an Ingress controller. One entry point serves many Services, unlike a LoadBalancer Service which creates one load balancer per Service."
Common mistakes
- Creating an Ingress without installing an Ingress controller.