kube-proxy: iptables vs IPVS
A cluster grows to thousands of Services, and in some kube-proxy modes each one can slow new connections. How do the iptables and IPVS modes find a backend, and what replaces the deprecated IPVS?
Play the animation 3 steps, animated, plays on a computer or a tablet
kube-proxy: iptables vs IPVS, step by step
-
In iptables mode the packet walks a chain box by box. It first enters KUBE-SERVICES and jumps to the per-Service KUBE-SVC chain that picks an endpoint by statistic random, and then a KUBE-SEP chain DNATs the packet to that Pod, here 10.244.2.7. KUBE-SERVICES has a rule per Service and the kernel checks them in order, so the walk grows O(n) with the number of Services.
Play from step 1 -
In IPVS mode the same kind of connection skips the walk. The Service is a virtual server and its endpoints are real servers in an in-kernel hash table, so one constant-time lookup finds a backend however many Services exist. Here it is 10.244.3.9, picked by a scheduling algorithm such as round-robin (the default) or least-connection.
Play from step 2 -
Either mode turns the ClusterIP into a ready backend, and at scale they differ in the lookup. With thousands of Services the iptables chain is thousands of rules long and every new rule slows the walk, while the IPVS hash stays one step. Large clusters long preferred IPVS for that, but it has been deprecated since v1.35 and may be removed in a future release, with nftables as its replacement.
Play from step 3