From point A to point B
Point A: you use Kubernetes services every day, but you don't know who turns the service IP into a pod IP. Point B: by the end of this chapter you'll be able to explain why kube-proxy with iptables doesn't scale, replace it with Cilium, prove that traffic keeps flowing even if the agent goes down, and give your services external IPs without a cloud load balancer.
Recap: service types
Pod IPs aren't stable: when a pod dies, its IP goes back to the pool and can end up on another one. That's why the service exists: a fixed virtual IP (VIP) and DNS name that spread traffic across the ready pods matching a label selector.
| Type | What it does |
|---|---|
| ClusterIP (default) | A VIP reachable only inside the cluster |
| NodePort | Opens the same port (30000-32767) on every node |
| LoadBalancer | An external IP, from the cloud or from Cilium's LB IPAM |
| Headless | No VIP: DNS returns the pod IPs directly; useful with StatefulSets |
kube-proxy and its limit
kube-proxy runs as a DaemonSet on every node. It watches services and EndpointSlices and programs rules on the node to translate the VIP to a pod. It can use iptables, IPVS or nftables; for years, iptables was the norm.
iptables chains versus a lookup in an eBPF map. Diagram: The House of Routing.
The problem: iptables was designed more than twenty years ago for static firewalls. Every service and every backend adds rules that are walked in order, and every change forces them to be rewritten. If you have a cluster with kube-proxy, measure it yourself:
# Backend rules kube-proxy wrote on a node
docker exec kind-worker iptables-save -t nat | grep -c KUBE-SEP
# Create 100 services on the same deployment and count again
for i in $(seq 1 100); do kubectl expose deployment web --port=80 --name=web-$i; done
docker exec kind-worker iptables-save -t nat | grep -c KUBE-SEP
The number grows with every service. In large clusters, that growth shows up in latency and CPU.
Cilium replaces kube-proxy
With kube-proxy replacement (KPR), Cilium resolves services with eBPF: it looks up the VIP in a map and rewrites the destination to a backend. Often it does this at the socket itself, when the application calls connect(), before the packet even exists.
Create a cluster without kube-proxy:
# kind-no-kube-proxy.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
networking:
disableDefaultCNI: true
kubeProxyMode: "none"
Without kube-proxy there's a chicken-and-egg problem: the agent needs to talk to the API server, but the kubernetes.default VIP was resolved by kube-proxy. That's why, with Helm, you give it the API server's real address:
kind create cluster --config kind-no-kube-proxy.yaml
helm install cilium cilium/cilium --version 1.20.3 -n kube-system \
--set kubeProxyReplacement=true \
--set k8sServiceHost=kind-control-plane \
--set k8sServicePort=6443
cilium status --wait
# Confirm the replacement and its details
kubectl -n kube-system exec ds/cilium -- cilium-dbg status --verbose | grep -A 12 "KubeProxyReplacement Details"
Among other things, the output shows the translation mode (SNAT; you'll see DSR in chapter 8), backend selection (random by default; Maglev is optional) and the service types it covers: ClusterIP, NodePort, LoadBalancer, externalIPs and HostPort.
Deploy the application from chapter 3 (lab-app.yaml) and repeat the 100-service test:
kubectl apply -f lab-app.yaml
for i in $(seq 1 100); do kubectl expose deployment web --port=80 --name=web-$i; done
docker exec kind-worker iptables-save -t nat | grep -c KUBE-SEP
# 0
# Services live in an eBPF map
kubectl -n kube-system exec ds/cilium -- cilium-dbg service list | head
Zero iptables rules, and every service shows up in the map with its VIP and its backends.
If the agent goes down
Cilium separates the control plane from the datapath. The agent writes the maps; the eBPF programs read them. If the agent restarts, the programs and maps stay in the kernel and traffic keeps flowing.
Simulate it in your lab (never in production). This patch makes the DaemonSet match no node and removes every agent:
kubectl -n kube-system patch daemonset cilium --type=merge \
-p '{"spec":{"template":{"spec":{"nodeSelector":{"lab":"no-agent"}}}}}'
kubectl -n kube-system get daemonset cilium # DESIRED 0
# The service keeps responding
kubectl exec client -- curl -s -o /dev/null -w "%{http_code}\n" http://web
The trade-off: with no agent, nobody updates the maps. If a backend dies now, the datapath will keep sending it traffic and you'll see timeouts. Bring the agents back and everything reconciles:
kubectl -n kube-system patch daemonset cilium --type=json \
-p='[{"op":"remove","path":"/spec/template/spec/nodeSelector/lab"}]'
cilium status --wait
Session affinity and traffic policies
KPR honors the same behaviors you expect from a Kubernetes service.
Session affinity
With sessionAffinity: ClientIP, requests from the same client IP always go to the same pod. Try it with an application that replies with its hostname:
apiVersion: apps/v1
kind: Deployment
metadata:
name: whoami
spec:
replicas: 3
selector:
matchLabels:
app: whoami
template:
metadata:
labels:
app: whoami
spec:
containers:
- name: whoami
image: traefik/whoami
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: whoami
spec:
sessionAffinity: ClientIP
selector:
app: whoami
ports:
- port: 80
# With affinity: the same Hostname five times
for i in 1 2 3 4 5; do kubectl exec client -- curl -s http://whoami | grep Hostname; done
Remove sessionAffinity and the name will keep changing. Use it only when an application keeps state in memory: it reduces load-balancing flexibility. Ideally, the application shouldn't need it.
Traffic policies
| Field | Cluster (default) | Local |
|---|---|---|
internalTrafficPolicy | Internal traffic to any backend in the cluster | Only to backends on the same node; useful for per-node log or metrics agents |
externalTrafficPolicy | Any node forwards, but the source IP changes | Only nodes with a backend; preserves the client's real IP |
With Cluster, the backend sees the node's IP; with Local, it sees the client's. Diagram: The House of Routing.
Be careful with Local: if a node has no backend, it doesn't forward. With internalTrafficPolicy: Local, pods on that node will see the service as empty; with externalTrafficPolicy: Local, external traffic arriving at that node is dropped.
External IPs with LB IPAM
In the cloud, a LoadBalancer service gets its external IP from the provider. In your lab or your data center, it stays at <pending> forever. Cilium's LB IPAM solves that: it's always on, but it does nothing until you create the first pool.
kubectl expose deployment web --name=web-lb --type=LoadBalancer --port=80
kubectl get service web-lb # EXTERNAL-IP: <pending>
# lb-pool.yaml
apiVersion: cilium.io/v2
kind: CiliumLoadBalancerIPPool
metadata:
name: lab-pool
spec:
allowFirstLastIPs: "No" # in quotes: it's a string, not a boolean
blocks:
- cidr: 172.20.50.0/24
kubectl apply -f lb-pool.yaml
kubectl get service web-lb # EXTERNAL-IP: 172.20.50.1
By default the operator can assign every address in the block, including the first and last (network and broadcast). allowFirstLastIPs: "No" reserves them. Another option is to define the block with start and stop.
You can have several pools and limit who uses each one with serviceSelector. The special key io.kubernetes.service.namespace selects by namespace:
apiVersion: cilium.io/v2
kind: CiliumLoadBalancerIPPool
metadata:
name: payments-prod
spec:
allowFirstLastIPs: "No"
blocks:
- cidr: 172.20.60.0/24
serviceSelector:
matchLabels:
io.kubernetes.service.namespace: payments
environment: production
Avoid overlapping selectors: if two pools match the same service, the result is undefined. And remember that LB IPAM only assigns the IP; for the network to reach it, you have to advertise it with BGP or at layer 2 (chapter 10).
Challenge
Answer before you open the solution.
1. Why does kube-proxy with iptables scale poorly?
Because rules grow with every service and backend, are walked in order and are rewritten with every change. Cilium does a lookup in an eBPF map.
2. Without kube-proxy, why do you have to set k8sServiceHost and k8sServicePort?
Because nothing resolves the API server's VIP yet, and the agent needs to talk to it to start.
3. You remove the agents. Does the service keep responding? What's the risk?
Yes, it responds, because the programs and maps stay in the kernel. The risk: the maps aren't updated and can point to backends that no longer exist.
4. You need your backend to see the external client's real IP. What do you change?
externalTrafficPolicy: Local, knowing that only nodes with a backend will respond.
What you take away
- A service gives a stable VIP and name to a changing group of pods.
- kube-proxy with iptables grows with every service; Cilium's KPR resolves with an eBPF map.
- Without kube-proxy, Cilium needs the API server's real address.
- The datapath survives the agent going down, but its maps stay frozen.
- Affinity, traffic policies and LoadBalancer work the same; LB IPAM gives you external IPs without a cloud.
In the next chapter: Ingress and Gateway API with Cilium, the front door for external traffic with layer 7 control.
Official resources
- Kubernetes Without kube-proxydocs.cilium.io
- LoadBalancer IP Address Management (LB IPAM)docs.cilium.io
- Servicekubernetes.io
- Virtual IPs and Service Proxieskubernetes.io
- Service Internal Traffic Policykubernetes.io
- Cilium: Up and Running (book)isovalent.com
Source and credits. This chapter summarizes and paraphrases the official book Cilium: Up and Running by Nico Vibert, Filip Nikolic and James Laverack (O'Reilly Media, 2026). The summary was produced with AI and reviewed, verified and approved by Jesús Espinoza. The diagrams and code examples are original work by The House of Routing and were checked against the official Cilium documentation. Cilium: Up and Running, the cover image, and related trade dress are trademarks of O'Reilly Media, Inc. This content is not affiliated with or endorsed by O'Reilly Media or Isovalent.