Wednesday, August 27, 2025

Kubernetes: What is Ingress and Why Ingress controller is required ?

 


This is one of the most confusing (but important) distinctions in Kubernetes networking. Let’s break it down clearly:



🔹 What is an Ingress?

An Ingress is a Kubernetes API object that manages external HTTP/HTTPS access to services in a cluster.

It works at Layer 7 (Application Layer).

Ingress lets you define routing rules like:

example.com/app1 → routes to Service A

example.com/app2 → routes to Service B

api.example.com → routes to Service C

It also supports:

SSL/TLS termination

Path-based routing

Hostname-based routing


Think of Ingress as the “rules” that describe how requests should be routed.



🔹 What is an Ingress Controller?

An Ingress Controller is the actual implementation that reads Ingress rules and configures a reverse proxy / load balancer.

Common Ingress Controllers:

NGINX Ingress Controller (most popular)

Traefik

HAProxy

Cloud-specific (AWS ALB Ingress, GCP Load Balancer Ingress, etc.)

Without an Ingress Controller, the Ingress object is just a definition — it won’t actually route traffic.



🔹 How is Ingress different from Services / LoadBalancers?


Feature Service (ClusterIP/NodePort/LoadBalancer) Ingress

Layer Layer 4 (Transport Layer) Layer 7 (Application Layer)

Purpose Stable access to Pods, load-balancing across them Advanced routing for external traffic (HTTP/HTTPS)

External Exposure LoadBalancer service provisions a cloud LB Ingress typically uses 1 external LB and multiplexes traffic

Routing Routes by IP:Port Routes by Hostname/Path (e.g. /api, /app)

SSL/TLS Not handled directly Handled at Ingress (TLS termination)

Use Case Simple service access (DBs, gRPC, internal APIs) Complex web app routing (multi-service apps, APIs, microservices)




🔹 How They Work Together

1. Service: Provides stable IP + DNS inside the cluster, load balances across Pods.

2. Ingress + Ingress Controller:

Accepts external HTTP/HTTPS traffic.

Applies rules to map traffic → Services.

Reduces need for one LoadBalancer per Service (saves cost).



🔹 Example


Without Ingress:

Each Service exposed externally needs its own LoadBalancer (expensive, redundant).


With Ingress:

You use one LoadBalancer (e.g., AWS ELB) → forwards to Ingress Controller → Ingress rules distribute to multiple Services.



✅ In short:

Service/LoadBalancer = basic connectivity + load balancing (L4).

Ingress = smarter traffic routing + SSL + path/host-based rules (L7).

Ingress Controller = the “engine” that makes Ingress work (usually NGINX or Traefik).



Would you like me to also make a Mermaid diagram that shows User → Ingress Controller → Services → Pods, so it’s visually clear how traffic flows compared to a direct LoadBalancer Service?



Below is the sequence diagram that shows the communication 


sequenceDiagram

    participant User as External User (Browser/API Client)

    participant CloudLB as Cloud Provider Load Balancer (AWS ELB / GCP LB / Azure LB)

    participant IngressCtl as Ingress Controller (NGINX / Traefik)

    participant Ingress as Ingress Rules (Host/Path Routing)

    participant ServiceA as Service A (ClusterIP)

    participant ServiceB as Service B (ClusterIP)

    participant PodA as Pod A (on Node1)

    participant PodB as Pod B (on Node2)


    User->>CloudLB: Request https://app.example.com/api

    CloudLB->>IngressCtl: Forward traffic to Ingress Controller


    IngressCtl->>Ingress: Check rules (e.g., /api → Service A)

    Ingress->>ServiceA: Route request to Service A


    ServiceA->>PodA: Forward traffic (Pod on Node1)

    ServiceA->>PodB: Or forward traffic (Pod on Node2)


    Note over IngressCtl,Ingress: Ingress Controller enforces Ingress rules <br> (path/host based, SSL termination)

    Note over ServiceA,PodA: Service does L4 load balancing <br> across Pods

    Note over CloudLB,IngressCtl: Cloud LB exposes cluster externally <br> only 1 LB needed for many services




No comments:

Post a Comment