Network
Pod calls a Service
ClusterIP and kube-proxy
A ClusterIP isn't on any interface. See how iptables rewrites it to a real Pod IP and how conntrack keeps track. The virtual IP exists only as kernel rules on every node - no socket binds it, no cable carries it, and the client never finds out which Pod answered.
- Service
- web · ClusterIP 10.96.120.15:80
- Endpoints
- 10.244.1.12 · 10.244.2.17 · 10.244.2.18, all :8080
- Client
- web-…-kq9tw · 10.244.1.12
- Mechanism
- iptables DNAT + conntrack · kube-proxy
Read the whole lesson as text
1. Call the VIP
The app in web-…-kq9tw asks for http://web:80. kube-dns answers 10.96.120.15, the Service's ClusterIP, and the app sends its SYN there, from port 44872. But that address is on no interface: not in the Pod's netns, not on the node, not on any cable. It exists only as match conditions in iptables rules, and the SYN rides the Pod's default route toward the bridge gateway to find them.
- The app asks the cluster's DNS for web and gets the Service's ClusterIP back.
- The app connects to 10.96.120.15:80 and the kernel builds the SYN.
- The Pod's route table has no better idea, so the SYN goes to its gateway - the bridge - aimed at an address that exists nowhere.
2. Who wrote the rules
Pause the packet - it sits in the kernel for microseconds anyway - and see who built this switchboard. kube-proxy on node-1 holds watches on Services and EndpointSlices. When web and its three endpoints were written, its watch fired and it ran iptables-restore: one KUBE-SVC chain for the VIP, with three KUBE-SEP branches, one per Pod.
- Hours before this packet, kube-proxy's watch delivered the Service and its three endpoints.
- kube-proxy turned that into chains in the kernel, once, and got out of the way.
3. The rule walk
Back to the SYN. It enters the node's netns from the bridge, and the nat table runs before any routing decision. KUBE-SERVICES matches dst 10.96.120.15 dpt:80 and jumps to KUBE-SVC-QD4FJ…, where a three-way probability split picks one Pod - rule 3 this time, 10.244.2.18:8080 on node-2. DNAT rewrites the destination; the source stays 10.244.1.12, because Pod IPs route everywhere. conntrack writes down the translation.
- The SYN enters the node's netns from the bridge, and the nat table runs before any routing decision.
- A three-way probability split picks one endpoint: this time rule 3, on node-2.
- The destination is rewritten to the Pod's address and port; the source stays untouched.
4. An ordinary packet
With dst 10.244.2.18:8080 this is now the packet from the last lesson: node-1 routes it at flannel.1, wraps it in UDP 8472 with VNI 1, and node-2 unwraps it onto cni0 and up the veth into p8m4z. The server accepts and sees the client as 10.244.1.12:44872 - it has never heard of the VIP.
- With a Pod destination, this is now exactly the packet from the last lesson, and node-1 wraps it for the tunnel.
- It crosses as one UDP packet between the nodes.
- node-2 unwraps it, the bridge forwards it up the veth, and p8m4z takes it.
- The app answers 200 OK, addressed straight back to the client Pod.
5. The reply's secret
The 200 OK leaves p8m4z bound for 10.244.1.12, tunnels back to node-1 - the node that owns the conntrack entry - and there the kernel un-rewrites the source: 10.244.2.18:8080 becomes 10.96.120.15:80 again. The client reads a reply from exactly the address it dialed. It never learns which Pod answered, and a different connection may well land elsewhere.
- The reply tunnels back to node-1, the node that owns the translation.
- conntrack recognizes its own connection and swaps the source back to the VIP before the packet leaves the node.
- The client reads a reply from exactly the address it dialed. It never learns which Pod answered.
6. One pick per connection
Load balancing here is per connection, not per packet. The random pick runs once, when conntrack sees a NEW flow; every later packet of that flow is ESTABLISHED and takes the recorded translation without re-walking the chains. And the whole trick runs in the kernel: kube-proxy only ever wrote rules.
- Every packet of this connection now skips the walk: the dice were rolled once, at SYN time.
- kube-proxy never touches a packet; it wrote rules and left. node-2 has the same ones, so the VIP works from anywhere.
Summary
kube-proxy never relayed a byte - it wrote rules, and the kernel did the rest. A ClusterIP is a match condition, not a place: the SYN was rewritten to a Pod address before any routing decision, and conntrack kept the ledger so the reply could lie consistently. Every node carries the same rules, so the VIP works from anywhere.
Next lesson: DNS in the cluster