CILIUM · CILIUM: UP AND RUNNING · CHAPTER 11

Egress traffic

Which IP each pod leaves with, how to recognize each team and how much bandwidth it uses.

5 min readBook: Cilium: Up and RunningLevel: intermediate

From point A to point B

Point A: you control how traffic enters the cluster, but when a pod calls something outside, you don't know which IP it leaves with or who can recognize it. Point B: by the end of this chapter you'll understand masquerading, you'll give each team a fixed egress IP with Egress Gateway and you'll cap a pod's bandwidth with Bandwidth Manager.

Masquerading: why your pod leaves with the node's IP

Pod ranges are usually private (RFC 1918) and the outside network doesn't know how to send a reply back to them. What it does know are the node IPs. That's why, by default, when a packet leaves the cluster Cilium swaps its source IP for the node's. It's a many-to-one SNAT called masquerading.

Masquerading hides the pod address A pod with address 10.0.1.25 on a node with address 172.18.0.3 calls an external server. When the packet leaves the node, Cilium replaces the source with the node address, so the reply can come back. The external server sees 172.18.0.3 and cannot tell which pod or namespace made the request. NODE · 172.18.0.3 pod10.0.1.25 eBPFSNAT src 10.0.1.25 → src 172.18.0.3 external serversees 172.18.0.3 leaves the node the reply finds its way back · but which pod, which team? the server cannot tell

The reply comes back, but the pod's identity is lost. Diagram: The House of Routing.

Check it with an external server: a traefik/whoami container on the kind network that tells you which IP called it.

docker run -d --rm --network kind --name ext-server traefik/whoami
EXT=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ext-server)

kubectl run client --image=nicolaka/netshoot -- sleep infinity
kubectl get pod client -o wide                       # pod IP and its node
kubectl exec client -- curl -s http://$EXT | grep RemoteAddr
# RemoteAddr: 172.18.0.x:…   ← the node's IP, not the pod's

kubectl -n kube-system exec ds/cilium -- cilium-dbg status | grep Masquerading

Cilium doesn't masquerade traffic headed to its own node's PodCIDR or to the range you declare as routable with ipv4NativeRoutingCIDR (chapter 5). You can turn it off completely with enableIPv4Masquerade: false, but that only makes sense if the network knows how to route pod IPs.

iptables or eBPF, and ip-masq-agent

ModeHow to enable itNotes
iptablesDefaultWorks with any kernel
eBPFbpf.masquerade: trueMore efficient and flexible; requires kube-proxy replacement and is required by features such as Egress Gateway

With eBPF mode you can turn on ip-masq-agent to decide which destinations are not masqueraded. It's useful, for example, with Multi-Pool (chapter 4), where pods leave from several ranges:

# values-masq.yaml
kubeProxyReplacement: true
k8sServiceHost: kind-control-plane
k8sServicePort: 6443
bpf:
  masquerade: true
ipMasqAgent:
  enabled: true
# The ranges that aren't masqueraded by default: private and reserved
kubectl -n kube-system exec ds/cilium -- cilium-dbg bpf ipmasq list

To change them, create an ip-masq-agent ConfigMap in kube-system. After a minute, the agent replaces the default list with yours:

apiVersion: v1
kind: ConfigMap
metadata:
  name: ip-masq-agent
  namespace: kube-system
data:
  config: |
    nonMasqueradeCIDRs:
      - 10.0.0.0/8
      - 172.16.0.0/12
      - 192.168.0.0/16
    masqLinkLocal: true

With that list, traffic to 172.18.0.0/16 leaves with the pod's real IP. The external server sees it arrive, but doesn't know how to send the reply back to 10.x.x.x, and the connection hangs:

kubectl exec client -- curl -s -m 5 http://$EXT
# timeout: the reply can't find its way back

That's the dilemma: with masquerading you get connectivity but lose the source identity; without it, things only work if the network knows the pod ranges. A firewall that only sees the node IP can't tell which team or which application made the call.

Egress Gateway

Egress Gateway gives outgoing traffic a predictable IP based on who sends it. You define which pods, to which destinations, and through which node and with which IP they leave. Typical cases:

  • One IP per team: in shared clusters, each team leaves with its own IP and the audit logs know who it was.
  • SaaS IP allowlists: services such as managed databases or GitHub only accept known IPs. With node IPs that change, the connection breaks.
  • Per-environment firewalls: development can go out directly; production, only through controlled egress nodes.
Egress Gateway: one fixed IP per tenant Pods of the finance namespace and the marketing namespace run on ordinary workers. Matching traffic is tunnelled to a dedicated gateway node: finance leaves through kind-worker3 with egress IP 172.18.0.240 and marketing through kind-worker4 with 172.18.0.241. The external system can now tell the tenants apart and a firewall can allow each IP. finance podson any worker marketing podson any worker kind-worker3egress IP .0.240 kind-worker4egress IP .0.241 external system.240 = finance.241 = marketing tunneltunnel CiliumEgressGatewayPolicy: which pods · which destinations · which gateway and IP

Each team leaves through its egress node and with its own IP. Diagram: The House of Routing.

Requirements: kube-proxy replacement, eBPF masquerading and CRD-based identity allocation (the default). It isn't compatible with Cluster Mesh: the egress node has to be in the same cluster as the pods.

Lab: one egress IP per team

Two workers for the applications and two dedicated egress nodes, with a taint so they don't get pods:

# kind-egress.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  disableDefaultCNI: true
  kubeProxyMode: "none"
nodes:
  - role: control-plane
  - role: worker
  - role: worker
  - role: worker            # kind-worker3: egress for finance
    kubeadmConfigPatches:
      - |
        kind: JoinConfiguration
        nodeRegistration:
          taints:
            - key: egress-gw
              effect: NoSchedule
  - role: worker            # kind-worker4: egress for marketing
    kubeadmConfigPatches:
      - |
        kind: JoinConfiguration
        nodeRegistration:
          taints:
            - key: egress-gw
              effect: NoSchedule
kind create cluster --config kind-egress.yaml
helm install cilium cilium/cilium --version 1.20.3 -n kube-system \
  --set kubeProxyReplacement=true \
  --set k8sServiceHost=kind-control-plane --set k8sServicePort=6443 \
  --set bpf.masquerade=true \
  --set egressGateway.enabled=true
cilium status --wait

# A secondary IP on each egress node
docker exec kind-worker3 ip addr add 172.18.0.240/16 dev eth0
docker exec kind-worker4 ip addr add 172.18.0.241/16 dev eth0
kubectl label node kind-worker3 egress-gw=finance
kubectl label node kind-worker4 egress-gw=marketing

One policy per team. It answers three questions: which pods (selectors), where to (destinationCIDRs, with optional excludedCIDRs) and which way they leave (egressGateway):

# egress-finance.yaml · cluster-scoped resource: no namespace
apiVersion: cilium.io/v2
kind: CiliumEgressGatewayPolicy
metadata:
  name: finance-egress
spec:
  selectors:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: finance
  destinationCIDRs:
    - 172.18.0.0/16
  egressGateway:
    nodeSelector:
      matchLabels:
        egress-gw: finance
    egressIP: 172.18.0.240     # or interface: eth0, but never both

The marketing one is the same, with its namespace, egress-gw: marketing and 172.18.0.241.

kubectl apply -f egress-finance.yaml -f egress-marketing.yaml
for ns in finance marketing; do
  kubectl create namespace $ns
  kubectl -n $ns run client --image=nicolaka/netshoot -- sleep infinity
done
kubectl run client --image=nicolaka/netshoot -- sleep infinity      # and one in default, with no policy
kubectl wait --for=condition=Ready pod/client -n finance
kubectl wait --for=condition=Ready pod/client -n marketing
kubectl wait --for=condition=Ready pod/client

kubectl -n finance   exec client -- curl -s http://$EXT | grep RemoteAddr   # 172.18.0.240
kubectl -n marketing exec client -- curl -s http://$EXT | grep RemoteAddr   # 172.18.0.241
kubectl exec client -- curl -s http://$EXT | grep RemoteAddr                # its node's IP

# Which pod leaves through which gateway and with which IP
kubectl -n kube-system exec ds/cilium -- cilium-dbg bpf egress list

In the table, Gateway IP is the egress node. Egress IP is 0.0.0.0 on every node except the gateway, which is where the SNAT happens.

Good to know. From the pod's node to the egress node, traffic always travels through a VXLAN tunnel, even if the cluster uses native routing. If you see it in a capture, it isn't a mistake.
High availability

You can list several egress nodes with egressGateways; each pod is pinned to one of them. But there's no automatic failover for existing connections: if the node changes, those connections are cut. If no node matches the selector, the affected traffic is dropped. Keep this in mind in your design.

Bandwidth Manager

Controlling egress also means controlling how much bandwidth each pod uses. A few noisy pods can saturate a node's link. Bandwidth Manager enforces per-pod limits with eBPF and an efficient queue (EDT), far better than the classic Kubernetes plugin.

  • You enable it with bandwidthManager.enabled=true. With bandwidthManager.bbr=true it also uses BBR congestion control.
  • You configure it with the standard kubernetes.io/egress-bandwidth annotation on the pod.
  • It doesn't work in kind: it needs access to global kernel settings. Try it on virtual machines or in the cloud.
apiVersion: v1
kind: Pod
metadata:
  name: backup-job
  annotations:
    kubernetes.io/egress-bandwidth: "50M"     # at most 50 Mbit/s outbound
spec:
  containers:
    - name: backup
      image: nicolaka/netshoot
      command: ["sleep", "infinity"]
kubectl -n kube-system exec ds/cilium -- cilium-dbg status | grep BandwidthManager
# BandwidthManager:  EDT with BPF [CUBIC] [eth0]

# Measure before and after with iperf3 or netperf between two pods on different nodes

There's also kubernetes.io/ingress-bandwidth, but limiting ingress comes too late: the traffic has already crossed the wire. Always limit at the source.

# Cleanup
docker rm -f ext-server

Challenge

Answer before you open the solution.

1. Why does Cilium masquerade by default?

Because the outside network doesn't know how to route the pods' private IPs and without SNAT the reply wouldn't come back.

2. You turn off masquerading toward an external network and the connection hangs. What's missing?

A return route: the external server receives the pod's IP, but doesn't know how to reach it.

3. Which three questions does a CiliumEgressGatewayPolicy answer?

Which pods, to which destinations, and through which node and with which IP they leave.

4. How do you limit a pod to 50 Mbit/s outbound?

With the kubernetes.io/egress-bandwidth: "50M" annotation and Bandwidth Manager enabled.

What you take away

  • Masquerading gives you connectivity at the cost of losing the pod's identity.
  • eBPF mode is more efficient and enables ip-masq-agent; Egress Gateway requires it.
  • Egress Gateway gives each team or application a fixed, auditable egress IP.
  • There's no automatic connection failover between egress nodes: design with that in mind.
  • Bandwidth Manager limits per-pod egress with an annotation.

In the next chapter you step into security: network policies, identities and how Cilium decides which traffic gets through.

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