Sub topic 13
How kube-proxy implements Services
This chapter assumes you know Pods, Deployments, and ClusterIP Services, and that you can read EndpointSlices. Here you will see what actually happens on a node when a Pod connects to a Service IP.
A Service IP is not a real interface
A ClusterIP is a virtual IP. No network interface owns it, and no process listens on it. Traffic to it works because every node has rules that rewrite the destination to a real Pod IP. This is destination NAT (DNAT).
kube-proxy is the node agent that installs those rules. It runs on each node, usually as a DaemonSet. It watches the API server for Services and EndpointSlices, then keeps the node's packet rules in sync.
Implementation modes
kube-proxy supports several modes. Your cluster picks one at install time.
| Mode | How it works | Notes |
|---|---|---|
| iptables | Chains of NAT rules. A random match picks a backend. | Long-standing default on Linux. Rule updates and lookups slow down with many Services. |
| ipvs | Uses the kernel IPVS load balancer with a hash table. | Scales better and offers more algorithms, such as round robin and least connection. |
| nftables | Uses nftables instead of iptables. | Newer. Intended to scale better than iptables. |
Some CNI plugins replace kube-proxy and handle Services themselves. In that case the commands below will show nothing.
What the rules look like
For a Service with three ready Pods, iptables mode creates a chain for the Service and one chain per endpoint. The Service chain uses probabilities, so each Pod gets roughly a third of new connections. Load balancing happens per connection, not per request. A client that keeps one connection open stays on one Pod.
You can inspect the rules on a node, for example:
kubectl -n kube-system get pods -l k8s-app=kube-proxy
kubectl -n kube-system logs -l k8s-app=kube-proxy --tail=20
sudo iptables -t nat -L KUBE-SERVICES -n | grep webThe first two commands show whether kube-proxy is running and which mode it chose. The last runs on the node itself and lists the Service entries. Chain names vary between versions, so treat the output as a guide.
Which backends are used
kube-proxy programs only endpoints in the EndpointSlice that are ready. A Pod failing its readiness probe is removed from the rules, so new connections skip it. Existing connections are tracked by conntrack, the kernel's connection table, and may continue until they end.
Common errors
- Service IP does not respond but Pod IPs do. Check that kube-proxy is running on that node. A crashed or missing kube-proxy leaves stale or absent rules.
- Pinging a ClusterIP fails. This is expected. The rules match only the Service's declared protocol and ports, and ICMP is not one of them.
- Stale rules after a change. Rule syncs are periodic and event driven, so brief delays happen. Persistent staleness points to a kube-proxy problem.
- Wrong mode assumed. Running
iptablescommands on an IPVS node shows little. Check the mode first.
Exercise
A Pod can reach another Pod directly by IP, but connections to the Service IP in front of it time out from one node only. What is a likely cause, and where do you look first?
Show answer
kube-proxy is probably not running or not syncing on that node, so the DNAT rules are missing. Check the kube-proxy Pod on that node with kubectl -n kube-system get pods -o wide and read its logs. If the cluster uses a CNI that replaces kube-proxy, check that component instead.