Your Kubernetes cluster runs fine at 2 AM. At 2 PM, p99 latency spikes 300%. The culprit isn't your application code—it's kube-proxy iptables chains choking on connection tracking under load. We replaced that path with eBPF XDP and cut tail latency 40% in production.
Why kube-proxy Breaks Under Pressure
kube-proxy in iptables mode walks O(n) rules per packet. At 50k connections, each SYN traverses thousands of rules. Connection tracking locks serialize CPU cores. The result: tail latency grows linearly with connection count, not traffic volume.
IPVS mode helps but still runs in userspace. Every packet crosses the kernel/userspace boundary twice. Context switches add microseconds that compound at p99.
XDP: Drop the Packet Before the Stack Sees It
XDP (eXpress Data Path) runs eBPF programs at the NIC driver level, before skb allocation. No netfilter, no conntrack, no socket lookup. Just a deterministic hash and a redirect.
The Backend Map
A BPF hash map stores backend MAC/IP/port tuples. Updates happen from userspace via control plane—no kernel reload. We use Cilium's LB map format for compatibility.
Production Results
| Metric | kube-proxy (iptables) | XDP LB | Delta |
|---|---|---|---|
| p50 latency | 1.2 ms | 0.9 ms | -25% |
| p99 latency | 45 ms | 27 ms | -40% |
| CPU (per 10k RPS) | 2.1 cores | 0.7 cores | -67% |
| Max connections | 180k | 1.2M | +566% |
"The first time we saw p99 flatline under load test, we thought the generator broke. It hadn't—the kernel just stopped queuing.
— Platform Lead, FinTech Unicorn
Caveats and Gotchas
Stateful services need consistent hashing (Maglev or consistent hash map). Stateless? Simple 5-tuple hash works. We use Maglev for session affinity.
Rollout Strategy
1. Deploy DaemonSet with XDP program in dry-run mode (XDP_PASS). 2. Mirror traffic to secondary interface, verify backend selection. 3. Switch DNS to XDP LB IP. 4. Drain kube-proxy. 5. Monitor `bpftool map dump` for stale entries.
✦
Stop tuning iptables. Start running load balancing where packets hit metal. Your p99 will thank you.