CILIUM · CILIUM: UP AND RUNNING · CHAPTER 8

Network performance

Fewer hops and closer backends: six features to get the most out of your network.

6 min readBook: Cilium: Up and RunningLevel: intermediate

From point A to point B

Point A: your network with Cilium works, but you haven't touched anything to make it faster. Point B: by the end of this chapter you'll know six performance features, what problem each one solves and when it's worth turning it on.

They all pursue the same goal: fewer hops, both on the network and inside the Linux stack, and preferring the closest backend when there is one.

Where each performance feature acts At the zone level, Service Traffic Distribution prefers backends in the client's zone. At the node level, Local Redirect Policy keeps traffic on the same node, XDP processes packets at the network driver, and netkit replaces veth. At the edge, Direct Server Return answers clients directly and Maglev keeps the same flow on the same backend. ZONE NODE EDGE Traffic Distributionprefer the client's zoneless latency, less cost Local Redirect Policystay on the same node XDPact at the network driver netkitreplaces veth DSRbackend answers the clientkeeps the client IP Maglevsame flow, same backendon any node common goal: fewer hops in the network and in the Linux stack

Where each feature acts. Diagram: The House of Routing.

The book deliberately leaves out BBR (modern congestion control), BIG TCP (larger packets for large transfers) and eBPF host routing, which Cilium already turns on by default if the kernel allows it.

Zone-aware traffic distribution

Spreading a cluster across zones (cloud availability zones or data centers) improves resilience, but crossing zones adds latency and, in the cloud, costs money. A service's trafficDistribution field tells Kubernetes to prefer backends close to the client.

ValueWhat it prefers
PreferSameZoneBackends in the same zone as the client
PreferSameNodeBackends on the same node; if there are none, in the same zone
PreferCloseOld name; since Kubernetes 1.34 it's equivalent to PreferSameZone

With Cilium you turn it on with loadBalancer.serviceTopology=true, and it requires kube-proxy replacement. To test it, create a kind cluster with four workers in two zones:

# kind-zones.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: worker
    labels: {topology.kubernetes.io/zone: zone-a}
  - role: worker
    labels: {topology.kubernetes.io/zone: zone-a}
  - role: worker
    labels: {topology.kubernetes.io/zone: zone-b}
  - role: worker
    labels: {topology.kubernetes.io/zone: zone-b}
networking:
  disableDefaultCNI: true
  kubeProxyMode: "none"
helm install cilium cilium/cilium --version 1.20.3 -n kube-system \
  --set kubeProxyReplacement=true \
  --set k8sServiceHost=kind-control-plane --set k8sServicePort=6443 \
  --set loadBalancer.serviceTopology=true

kubectl create deployment whoami --image=traefik/whoami --replicas=8
kubectl expose deployment whoami --port=80
kubectl get pods -o wide        # spread across the two zones

From a client in zone-a, responses come from any zone. Add the preference and repeat:

kubectl run client --image=nicolaka/netshoot \
  --overrides='{"spec":{"nodeName":"kind-worker"}}' -- sleep infinity

kubectl patch service whoami -p '{"spec":{"trafficDistribution":"PreferSameZone"}}'

# Now only the pods in zone-a respond
for i in $(seq 20); do kubectl exec client -- curl -s http://whoami | grep Hostname; done | sort | uniq -c
  • If there are no backends in the client's zone, traffic goes to another zone.
  • internalTrafficPolicy or externalTrafficPolicy set to Local take priority over trafficDistribution.
  • It works well if traffic arrives spread across zones. If almost all of it originates in a single zone, that zone's backends get saturated.

Local Redirect Policy

Some applications run on every node as a DaemonSet: DNS caches, log agents, metrics collectors. Without help, a pod can end up talking to the copy on another node. A Local Redirect Policy (LRP) intercepts traffic to a service or an IP and sends it to the backend on the same node.

Frontend typeWhat it interceptsExample
serviceMatcherA ClusterIP service by name and namespaceCluster DNS toward NodeLocal DNSCache
addressMatcherAn IP and a port169.254.169.254:80, the cloud metadata, toward a local cache

Turn it on with localRedirectPolicies.enabled=true and restart the operator and the agents. kube-proxy replacement is recommended, but not required. This policy sends traffic for the whoami service only to the local copy:

apiVersion: cilium.io/v2
kind: CiliumLocalRedirectPolicy
metadata:
  name: whoami-local
spec:
  redirectFrontend:
    serviceMatcher:            # which traffic is intercepted
      serviceName: whoami
      namespace: default
  redirectBackend:
    localEndpointSelector:     # which local pods it's sent to
      matchLabels:
        app: whoami
    toPorts:
      - port: "80"
        protocol: TCP
# On the agent of the client's node, the service becomes type LocalRedirect
AGENT=$(kubectl -n kube-system get pods -l k8s-app=cilium \
  --field-selector spec.nodeName=kind-worker -o name)
kubectl -n kube-system exec $AGENT -- cilium-dbg service list | grep LocalRedirect

The most common case is NodeLocal DNSCache: a DNS cache DaemonSet on every node and an LRP with serviceMatcher on kube-dns in kube-system, ports 53 UDP and TCP, pointing to the cache pods. DNS queries stop leaving the node.

Direct Server Return (DSR)

When an external client comes in through a node that doesn't have the backend, that node forwards the request to another one and, by default, applies SNAT. The backend sees the node's IP and the response goes back through the same node. With DSR, the backend sees the client's real IP and replies to it directly.

Without and with Direct Server Return Without DSR, the client reaches node 1, node 1 forwards to the backend on node 2 with its own source address, and the reply goes back through node 1. With DSR, node 1 forwards the request keeping the client address, and the backend on node 2 replies straight to the client. SNAT · DEFAULT DSR client node 1NodePort node 2 backend backend sees node 1's address reply returns through node 1 client node 1NodePort node 2 backend backend sees the real client IP reply goes straight to the client

With DSR the response doesn't take the long way back. Diagram: The House of Routing.

Requirements: kube-proxy replacement and native routing or a Geneve tunnel; it doesn't work with VXLAN.

# values-dsr.yaml
kubeProxyReplacement: true
k8sServiceHost: kind-control-plane
k8sServicePort: 6443
routingMode: native
ipv4NativeRoutingCIDR: 10.0.0.0/8
autoDirectNodeRoutes: true
loadBalancer:
  mode: dsr

traefik/whoami replies with the address it sees in RemoteAddr. Publish it through NodePort and call it from a container outside the cluster:

kubectl create deployment whoami --image=traefik/whoami --replicas=2
kubectl expose deployment whoami --type=NodePort --port=80
PORT=$(kubectl get svc whoami -o jsonpath='{.spec.ports[0].nodePort}')
NODE=$(kubectl get node kind-control-plane -o jsonpath='{.status.addresses[0].address}')

docker run --rm --network kind nicolaka/netshoot sh -c \
  "ip -4 -br addr show eth0; curl -s http://$NODE:$PORT | grep RemoteAddr"
# Without DSR: RemoteAddr is an internal IP of the node
# With DSR: RemoteAddr is the client container's IP

kubectl -n kube-system exec ds/cilium -- cilium-dbg status --verbose | grep -i "mode"
kubectl -n kube-system exec ds/cilium -- cilium-dbg bpf lb list | grep -i dsr
externalTrafficPolicy: LocalDSR
ScopePer serviceThe whole cluster
Which nodes accept trafficOnly those with a backendAny
Return pathThrough the node's stackStraight to the client

XDP

XDP (eXpress Data Path) runs eBPF in the network card's driver, before the kernel does almost anything with the packet. It's ideal for dropping traffic early (DDoS protection, firewall) and for speeding up service load balancing. Unlike DPDK, it keeps cooperating with the kernel.

  • It only accelerates traffic coming in through a physical interface; traffic between pods on the same node doesn't go through there.
  • You turn it on with loadBalancer.acceleration=native. If you don't know whether your driver supports it, use best-effort, which turns it on only where it can.
  • It's not on by default because not every driver supports native XDP.

Maglev

By default, each node picks the backend at random. If the node handling a connection fails and the next packet comes in through another node, that node may pick a different backend. The new backend doesn't know the connection and replies with a TCP RST: the connection drops.

Maglev, an algorithm created by Google, uses consistent hashing over the connection's five fields (source IP and port, destination IP and port, protocol). Every node computes the same result with the same table, so the same flow lands on the same backend no matter where it comes in.

helm upgrade cilium cilium/cilium --version 1.20.3 -n kube-system \
  --reuse-values --set loadBalancer.algorithm=maglev
kubectl -n kube-system rollout restart daemonset/cilium

kubectl -n kube-system exec ds/cilium -- cilium-dbg status --verbose | grep "Backend Selection"
# Backend Selection:  Maglev (Table Size: 16381)

It requires kube-proxy replacement. It uses a fixed-size table, with somewhat more memory, so turn it on when you really have several entry nodes (for example, with BGP and ECMP) and need stable connections.

Try it. With Maglev on, pin the client's source port (curl --local-port 40000 …) and repeat the request every minute: the same backend will always respond. If you repeat it too quickly, the system still has the port in use and you'll see "Address in use".

netkit

The veth pair (chapter 5) is more than fifteen years old. It works at layer 2, so the pod needs ARP to reach its peer, and every packet crosses several layers before leaving the node.

netkit, included in Linux 6.7, moves the eBPF attach point inside the pod's namespace. The decision is made earlier and the packet goes straight to its next hop. Only the host side manages the programs, so a pod can't remove them. With Cilium it works at layer 3 by default, with no ARP.

# Requires kernel 6.7 or later and a new cluster
bpf:
  datapathMode: netkit

Early production users have measured notable performance gains; ByteDance, for example, reported around 10% more throughput.

Challenge

Answer before you open the solution.

1. You pay for cross-zone traffic. What do you change in your services?

trafficDistribution: PreferSameZone, with loadBalancer.serviceTopology=true in Cilium.

2. Which feature would you use so DNS queries don't leave the node?

A Local Redirect Policy with serviceMatcher on kube-dns, together with NodeLocal DNSCache.

3. Which routing mode doesn't DSR work with?

VXLAN encapsulation. It needs native routing or a Geneve tunnel.

4. An entry node goes down and TCP connections drop. What prevents it?

Maglev, because every node picks the same backend for the same flow.

What you take away

  • Zone: trafficDistribution prefers nearby backends and saves latency and cost.
  • Node: LRP keeps traffic local; XDP acts in the driver; netkit replaces veth.
  • Edge: DSR preserves the client's IP and shortens the way back; Maglev keeps each flow on its backend.
  • Almost all of them require kube-proxy replacement; turn them on when they solve a problem you actually have.

In the next chapter: Cluster Mesh, to connect several clusters with global services and policies.

Official resources

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.

Navigate