|
|
Kubernetes Ingress
Author: Venkata Sudhakar
A Kubernetes Ingress is a resource that routes external HTTP and HTTPS traffic into services inside your cluster. Without Ingress, the only way to expose a service to the internet is a LoadBalancer service, which creates one cloud load balancer per service - expensive and hard to manage. Ingress lets you use a single load balancer to route traffic to many services based on the hostname or URL path. Ingress works through an Ingress Controller - a pod running inside your cluster (typically nginx or the cloud provider's own controller) that reads your Ingress rules and configures the load balancer accordingly. You define the rules in an Ingress resource: requests to api.myapp.com go to the api service, requests to myapp.com/admin go to the admin service, and so on. The below example shows an Ingress that routes traffic to two services by path, and another that routes by hostname.
Apply and verify,
kubectl apply -f ingress.yaml
ingress.networking.k8s.io/myapp-ingress created
kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
myapp-ingress nginx myapp.com 34.105.12.200 80 30s
# Traffic routing:
# http://myapp.com/api/orders -> api-service:8080
# http://myapp.com/ -> frontend-service:3000
It gives the following output,
kubectl get ingress myapp-ingress-hosts
NAME CLASS HOSTS ADDRESS PORTS AGE
myapp-ingress-hosts nginx api.myapp.com,www.myapp.com 34.105.12.200 80, 443 1m
# One load balancer IP handles both hostnames
# TLS termination happens at the Ingress - services receive plain HTTP
# https://api.myapp.com -> api-service:8080 (HTTPS terminated at Ingress)
# https://www.myapp.com -> frontend-service:3000
Ingress vs LoadBalancer Service: use a LoadBalancer Service when you need TCP/UDP routing or non-HTTP protocols (databases, Kafka). Use Ingress for HTTP/HTTPS traffic to multiple services - it is far more cost-effective since one cloud load balancer handles all your services instead of one per service.
|
|