External Traffic Cluster vs Local
Behind a load balancer the app sees a Node IP by default, not the client. Local instead of Cluster in the Service externalTrafficPolicy fixes that but can load Pods unevenly. What does each value cost?
Play the animation 5 steps, animated, plays on a computer or a tablet
External Traffic Cluster vs Local, step by step
-
Service web is a LoadBalancer under the default externalTrafficPolicy Cluster, so every Node accepts its traffic. The balancer picks Node-3, which runs no Pod web. Node-3 SNATs the connection to its own address and forwards it across the cluster network to Pod web-3 on Node-2. With connections spread at random over all ready Pods, each Pod takes about a third.
Play from step 1 -
The SNAT is not only for forwarded traffic. The next connection lands on Node-1 and Pod web-1 on that same Node serves it, yet under Cluster its source is still replaced with a Node-1 address. The Pod never sees 198.51.100.9, so source IP allowlists and access logs lose the client, and a forwarded connection also pays an extra hop.
Play from step 2 -
With externalTrafficPolicy Local a Node serves only its own Pods, forwards nothing to other Nodes and does no SNAT, so Pod web-2 sees 198.51.100.9. The API server allocates healthCheckNodePort 32021, but until the balancer acts on that port, Node-3 still gets a third of connections and drops them for lack of a local Pod. Pods web-1 and web-2 split a third.
Play from step 3 -
The balancer probes /healthz on port 32021 of every Node. A healthy kube-proxy answers from its count of ready local endpoints: 200 from Node-1 with two and from Node-2 with one, 503 from Node-3 with none. The balancer marks Node-3 unhealthy and sends new connections only to Node-1 and Node-2.
Play from step 4 -
A balancer that cannot weight its targets spreads connections per Node, not per Pod. Node-1 and Node-2 get about half each, so the two Pods on Node-1 take a quarter apiece while Pod web-3 alone takes half. That uneven load is the second cost of Local. Spreading Pods evenly across Nodes, for example with topology spread constraints, reduces it.
Play from step 5