Network
Ingress and Gateway API
Host and path routing
One public IP, many apps: TLS termination and routing by host name and path. An ingress-nginx controller holds every certificate, reads the host and path inside the tunnel, and turns each into an ordinary Pod-to-Pod call inside the cluster.
- Entry
- ingress-nginx · LoadBalancer 203.0.113.50:443
- NodePort
- 30443 · on every node
- Routes
- shop.example.com · /api → api · / → web
- Certs
- Secret tls-shop · served by the controller
Read the whole lesson as text
1. To the edge
The visitor opens https://shop.example.com/api/orders, and public DNS has already answered 203.0.113.50. That address is a load balancer in front of an ingress-nginx controller - a plain Deployment of Pods, exposed by a Service of type LoadBalancer with HTTPS NodePort 30443 and externalTrafficPolicy: Local. Local means the load balancer only sends traffic to nodes that run a controller Pod. Its health check passes on node-1 and fails on node-2, so node-1 it is. The first packet is a SYN, like any TCP connection.
- The visitor's browser opens a connection to the load balancer on port 443.
- Only node-1 passes the health check, so the load balancer sends the packet there, to port 30443.
2. Into the controller
Zoom into node-1. Port 30443 is just another NodePort: kube-proxy's rules match it, pick the controller Pod's endpoint, and rewrite the destination from node-1:30443 to 10.244.1.20:443. Because the policy is Local, the rules only pick Pods on this node and skip the masquerade, so the source stays 198.51.100.7. The rewritten SYN goes out through the cni0 bridge and down the controller Pod's veth, and conntrack remembers the rewrite for every packet that follows.
- The node's rules recognise 30443 as the controller's Service.
- The rewritten packet is local, so the bridge hands it to the controller Pod.
3. The handshake
The TCP handshake completes and the visitor sends its first TLS message. The ClientHello carries the host name in the clear - the server_name extension, SNI - because the controller serves many hosts and needs it to pick a certificate. It answers with the one loaded from Secret tls-shop; the visitor checks the chain and the name, and after a single round trip both sides have keys. Everything after this is ciphertext to everyone but the controller.
- The visitor's first TLS message names the host it wants, unencrypted.
- The controller holds one certificate per host, loaded from Secrets.
- It sends the certificate; the visitor checks it, and one round trip later the tunnel is up.
4. Match the rules
The rules were in place long before this request. The controller watches Ingress objects, and the EndpointSlices of every Service they name, and rewrites its nginx config whenever they change - here one object maps shop.example.com to two backends. The request that arrives is ordinary HTTP once decrypted: GET /api/orders with Host shop.example.com. The controller matches the host first, then the longest path: /api goes to Service api, everything else to Service web.
- Standing state: the controller built its routing table from Ingress objects, and reloads when they change.
- The request arrives as ciphertext and is decrypted only at the controller.
5. Upstream call
Zoom back into node-1. To reach /api, the controller opens a brand-new TCP connection of its own. It doesn't dial Service api's ClusterIP: it already holds the Service's endpoints from its EndpointSlice watch, picks one itself - 10.244.2.19:8080, on node-2 - and connects straight to it. kube-proxy's rules see a Pod IP and do nothing, and the packet crosses the VXLAN tunnel like any Pod-to-Pod traffic. With the request the controller adds X-Forwarded-For, because the api Pod will only ever see the controller's own IP as its client.
- The controller looks up Service api's endpoints in its own memory and picks one.
- The SYN goes straight to the Pod IP, so kube-proxy's rules have nothing to rewrite.
- The SYN crosses to node-2 wrapped in VXLAN, like any Pod-to-Pod packet.
- The request is proxied with the visitor's address added and the original Host kept.
6. The response
The api Pod answers - plain HTTP, to a client it believes is the controller. The reply rides the tunnel back to node-1, where the controller encrypts it with the session keys and sends it down the visitor's own connection. conntrack and the load balancer undo their rewrites on the way out. The visitor has only ever spoken to 203.0.113.50; the certificates, the rules and the Pod addresses all stayed inside.
- The api Pod answers; its client, as far as it can tell, is the controller.
- The controller encrypts the reply, and every hop undoes its rewrite on the way out.
Summary
The controller is the only component in this story with certificates, and the only one that read the HTTP. Routing happened at layer 7 - host and path - inside a tunnel the visitor opened with 203.0.113.50. Behind it, the call to the api Pod was plain Pod-to-Pod traffic: the controller picked the Pod itself from the EndpointSlices, and the ClusterIP was never dialed.
Next lesson: NetworkPolicy