Ingress Controller Routing

You create an Ingress full of host and path rules, and on its own it serves nothing at all. What receives the traffic then, how does it usually pick a Pod, and what answers a request for a host that no rule names?

Play the animation 5 steps, animated, plays on a computer or a tablet

Ingress Controller Routing, Kubernetes diagram

Ingress Controller Routing, step by step

  1. The controller watches Ingress objects whose ingressClassName names its IngressClass. Ingress shop has a TLS entry for shop.io and two rules, both with pathType Prefix. Rule / goes to Service web and /api to Service api. The controller compiles them into its proxy config.

    Play from step 1
  2. External traffic reaches the controller through a Service of its own, usually a LoadBalancer or NodePort. An HTTPS request for shop.io/ lands on the controller Pod, which serves the certificate from Secret shop-tls, the one the Ingress TLS entry names for that host, and terminates TLS.

    Play from step 2
  3. Now the controller reads the Host header, shop.io, and the path, /. Only the / rule matches. The controller does not hand the request to the Service ClusterIP. Instead it reads the Ready endpoints of Service web from its EndpointSlice and proxies straight to Pod IP 10.244.1.5.

    Play from step 3
  4. A second HTTPS request asks for shop.io/api. Both rules match it, because Prefix / matches every path, and the Ingress spec gives precedence to the longest matching path, so /api wins. The controller reads the endpoints of Service api and proxies straight to Pod IP 10.244.2.7.

    Play from step 4
  5. A plain HTTP request for other.io/ arrives. No Ingress of this class names that host and Ingress shop sets no defaultBackend, so the Ingress API leaves the answer to the controller. This one hands the request to its own default backend, which answers 404, and no Service endpoints are read.

    Play from step 5

Sources