Skip to main content
Kubernetes internalsLesson 10 of 12

kube-proxy Modes, from Service IP to Pod IP

The packet lesson showed that a Service IP becomes a Pod IP on the sending node. Here we open that box: what kube-proxy writes into the kernel in each mode, how eBPF datapaths do the same job, and what conntrack and traffic policy change.

Mode—
Service lookup—
Endpoint picked—
Source IP at Pod—
Node AEndpointsAPI serverServices, EndpointSlicesExternal clientvia NodePort or LBClient Pod→ 10.96.12.34:80kube-proxyDaemonSet, watchesKernel rulesiptables · IPVS · nftconntrackone entry per floweBPF datapathsocket and tc hooksPod 110.244.1.5Pod 210.244.1.6Pod 3on Node BSYN 10.96.12.34
RequestWatchAppears in a later step

What you will learn

  • kube-proxy is a controller that programs rules, not a proxy in the path
  • iptables DNAT chains and random probability per endpoint
  • IPVS (deprecated) and nftables (GA) compared
  • eBPF kube-proxy replacement at the socket and tc level
  • conntrack, stale entries and externalTrafficPolicy: Local

The modes side by side​

iptablesIPVSnftableseBPF replacement (e.g. Cilium)
StatusDefault todayDeprecated since v1.35, removal plannedGA since v1.33, kernel 5.13+Outside Kubernetes, from the CNI
Service lookupWalks KUBE-SERVICES rulesHash table of virtual serversVerdict mapeBPF map
Endpoint choiceRandom, statistic --probabilityScheduler: rr, lc, sh and othersRandomChosen at connect() or per packet at tc/XDP
UpdatesLarge table rewritesPer virtual serverOnly what changedMap updates
Where to lookiptables-save -t natipvsadm -Lnnft list table ip kube-proxyCNI tools, e.g. cilium-dbg service list

Try it yourself​

# Which mode? (on a node; kind nodes: docker exec -it lab-worker bash)
curl -s localhost:10249/proxyMode # kube-proxy metrics port answers iptables / ipvs / nftables
kubectl logs -n kube-system ds/kube-proxy | grep -i proxier # e.g. "Using iptables Proxier"
kubectl get endpointslices -l kubernetes.io/service-name=web # the endpoints kube-proxy programs

# iptables mode
iptables-save -t nat | grep -E 'KUBE-SVC|KUBE-SEP' | head # chains and probability rules
iptables-save -t nat | grep -c KUBE-SEP # how many endpoint rules on this node

# nftables and IPVS mode
nft list table ip kube-proxy | less # maps and per-Service chains
ipvsadm -Ln # virtual servers and real servers

# conntrack
conntrack -L -d 10.96.12.34 # flows to this ClusterIP and their DNAT target
conntrack -D -p udp --orig-dst 10.96.0.10 # clear stale UDP entries to kube-dns by hand

Check yourself

  1. kube-proxy on one node crashes. What happens to traffic from Pods on that node to an existing Service?
  2. You scale a Deployment from 2 to 6 Pods, but a client with one long-lived TCP connection still talks to the same Pod. Why?
  3. A LoadBalancer Service uses externalTrafficPolicy: Local. Why does the app now see real client IPs?

Further reading: Virtual IPs and Service Proxies · Removal of the kube-proxy IPVS backend · Source IP for Services · Cilium kube-proxy replacement · A Packet from Pod to Pod · Finding Services by Name (Service·DNS) · Service Types (ClusterIP · NodePort · LoadBalancer)