Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Send a Pod's traffic out through an egress gateway

By updated

Improve this page

Without any setting, a packet leaving a Pod for the outside carries the address of the node where the Pod runs, and that address changes as soon as the Pod is rescheduled. The Cilium egress gateway fixes this: a CiliumEgressGatewayPolicy designates Pods and a destination, and the matching traffic leaves through a chosen node, with the address of that node. This lesson enables the feature on Cilium 1.20.5, writes the policy, proves the exit with the log of a server outside the cluster and reads the BPF table that applies it. It also shows the activation trap: an incomplete helm upgrade seems to succeed, then the Cilium agents crash. It is aimed at readers who already administer a Cilium cluster and have to get through a firewall that filters on the source address.

What you will learn

  • Say why outgoing traffic sometimes has to leave from a fixed address, and read the address the destination sees without a policy.
  • Enable the egress gateway with egressGateway.enabled=true and bpf.masquerade=true, and recognize the failure when bpf.masquerade is missing, with kubectl logs --previous.
  • Label an exit node and write a CiliumEgressGatewayPolicy: selected Pods, destination, node, interface.
  • Prove with the log of a witness server outside the cluster that the selected Pod leaves through the gateway, and that a non-selected Pod on the same node does not change.
  • Read cilium-dbg bpf egress list on the Pod's node and on the gateway.
  • Say what happens when no node matches, and what the limits of the feature are.

Prerequisites

  • The lesson Install Cilium without kube-proxy and choose your IPAM, which installs the cluster used in this lesson: Cilium 1.20.5 deployed with Helm, kubeProxyReplacement=true.
  • The lesson Pod Networking, to know how a Pod gets its address.
  • Know what a source address translation (masquerade) is: the guide NAT: SNAT, DNAT and port forwarding (in French) explains it.
  • ssh access to the nodes with sudo for helm, a kubectl that administers the cluster, and a machine outside the cluster that the nodes can reach, to run a witness server on.
  • The demonstration environment: three Ubuntu 24.04 VMs (net-cp, net-w1, net-w2, addresses 10.10.50.14, 10.10.50.15 and 10.10.50.16), Kubernetes 1.37.2, containerd 2.2.1 and Cilium in vxlan tunnel mode. The witness server runs on the workstation, at 10.10.50.1:8090.
  • The outputs were captured on 17 November 2026 with Cilium 1.20.4, except the Cilium: line of cilium status, captured with 1.20.5 on 18 November 2026. The commands in this lesson install 1.20.5. The lab, validated with 1.20.5, gave the same result: the witness sees sortie-controlee arrive from net-w2.lab and autre from net-w1.lab.

These addresses belong to the demonstration. On your side, replace them like this:

In the lessonWhat to use on your side
10.10.50.15the address of the node where the selected Pod runs (kubectl get nodes -o wide, INTERNAL-IP column)
10.10.50.16, node net-w2.labthe address and name of the node you pick as the exit
10.10.50.1:8090the address and port of your witness server, outside the cluster
enp1s0the network card of the exit node through which the traffic leaves (ip -br link lists them)

Why send traffic out through a fixed address?

An external service often filters its clients by source address: a corporate firewall, a managed database with an allow list, a partner's API. That list expects a few known addresses. A Pod, however, has no stable address as seen from the outside. When its traffic leaves the cluster (this is called egress, the exit), the node rewrites the packet's source address and puts its own: this is masquerade. The external service therefore sees the node's address, and sees a different one as soon as the Pod moves to another node.

There are two answers. You can allow every node of the cluster, which opens far more than necessary. Or you can send the wanted traffic out through one node with a fixed address, the exit node, or gateway. That is what the egress gateway does. It filters nothing: to limit what a Pod can reach, you write a NetworkPolicy. It only chooses where the traffic leaves the cluster.

How do you prepare the witness server and the two Pods?

To prove which address leaves the cluster, you need a machine that reads it. The witness server fits in a few lines of Python: it answers with the source address it sees and writes it to a log. It runs on a machine outside the cluster (the demonstration workstation), bound to the address the nodes can reach. You start it with python3 temoin.py temoin-journal.txt, and 10.10.50.1 is to be replaced with your address. The script of the demonstration is written in French and kept as is, because the lab checks its output: source vue par la destination means "source seen by the destination", chemin means "path", and journal means "log".

import datetime
import http.server
import sys
JOURNAL = sys.argv[1]
class Temoin(http.server.BaseHTTPRequestHandler):
def do_GET(self):
source = self.client_address[0]
ligne = f"{datetime.datetime.now().isoformat(timespec='seconds')} source={source} chemin={self.path}\n"
with open(JOURNAL, "a", encoding="utf-8") as f:
f.write(ligne)
corps = f"source vue par la destination : {source}\n".encode()
self.send_response(200)
self.send_header("Content-Length", str(len(corps)))
self.end_headers()
self.wfile.write(corps)
def log_message(self, *args):
pass
http.server.ThreadingHTTPServer(("10.10.50.1", 8090), Temoin).serve_forever()

The path of each request (/vise, /non-vise, meaning "selected" and "not selected") serves as a label in the log: that way you can tell which command produced which line.

On the cluster side, you need two Pods on the same node, each with a different app label. The nodeName field places them on net-w1.lab. Replace it with one of your workers:

apiVersion: v1
kind: Pod
metadata:
name: sortie-controlee
namespace: egress-demo
labels:
app: sortie-controlee
spec:
nodeName: net-w1.lab
containers:
- name: c
image: busybox:1.37@sha256:a7dbc319b1438115a207e11930dc4bb3e643dcb3ec0bdd694bb36cd8fad289ec
command: ["sleep", "3600"]
---
apiVersion: v1
kind: Pod
metadata:
name: autre
namespace: egress-demo
labels:
app: autre
spec:
nodeName: net-w1.lab
containers:
- name: c
image: busybox:1.37@sha256:a7dbc319b1438115a207e11930dc4bb3e643dcb3ec0bdd694bb36cd8fad289ec
command: ["sleep", "3600"]

Create the namespace, apply the two Pods (file pods.yaml), then read their addresses:

Terminal window
kubectl create namespace egress-demo
kubectl apply -f pods.yaml
kubectl -n egress-demo wait --for=condition=Ready pod --all --timeout=120s
kubectl -n egress-demo get pods -o wide
namespace/egress-demo created
pod/sortie-controlee created
pod/autre created
pod/autre condition met
pod/sortie-controlee condition met
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
autre 1/1 Running 0 1s 10.244.1.29 net-w1.lab <none> <none>
sortie-controlee 1/1 Running 0 1s 10.244.1.115 net-w1.lab <none> <none>

Here is what the destination sees before any policy. Send a request from sortie-controlee:

Terminal window
kubectl -n egress-demo exec sortie-controlee -- wget -qO- -T 5 http://10.10.50.1:8090/sans-politique
source vue par la destination : 10.10.50.15

The server sees 10.10.50.15, the address of net-w1, not that of the Pod (10.244.1.115). This is the starting state: you want to change it for only one of the two Pods.

Which Cilium settings enable the gateway?

The egress gateway needs three settings. Cilium must replace kube-proxy (kubeProxyReplacement=true), the gateway must be enabled (egressGateway.enabled=true), and masquerade must be done by BPF (bpf.masquerade=true) instead of iptables. BPF is the Linux kernel mechanism through which Cilium processes packets; by default, masquerade still goes through iptables.

A fourth point comes from the Cilium 1.20 documentation: the gateway is not compatible with the kvstore identity mode. Cilium must use Kubernetes as its identity store, that is identityAllocationMode set to crd, which is the default for new installations. The check is a read of the ConfigMap, which must display crd. The demonstration did not capture this value:

Terminal window
kubectl -n kube-system get configmap cilium-config -o jsonpath='{.data.identity-allocation-mode}'; echo

The Cilium documentation also declares the gateway incompatible with CiliumEndpointSlice: do not enable it on this cluster.

The starting state of the cluster is read in cilium status. The Masquerading line tells how masquerade is done:

Terminal window
kubectl -n kube-system exec ds/cilium -c cilium-agent -- cilium status | grep -E 'KubeProxyReplacement|Masquerading|Routing|Cilium:'
KubeProxyReplacement: True [enp1s0 10.10.50.15 fe80::5054:8bff:fed2:14 (Direct Routing)]
Cilium: Ok 1.20.5 (v1.20.5-15012141)
Routing: Network: Tunnel [vxlan] Host: Legacy
Masquerading: IPTables [IPv4: Enabled, IPv6: Disabled]

KubeProxyReplacement: True is already in place, but Masquerading is IPTables. It has to become BPF, and this is the change people forget.

What happens if bpf.masquerade is missing?

The mistake is natural: you enable egressGateway.enabled=true and leave masquerade as it is, in iptables. Helm accepts the command and answers "Upgrade complete", with no warning at all. The output below comes from a test where bpf.masquerade=false is set explicitly. A first test, without this option, gave the same agents in CrashLoopBackOff.

Terminal window
sudo helm --kubeconfig /etc/kubernetes/admin.conf upgrade cilium cilium/cilium \
-n kube-system --version 1.20.5 --reuse-values \
--set egressGateway.enabled=true --set bpf.masquerade=false
Release "cilium" has been upgraded. Happy Helming!
NAME: cilium
LAST DEPLOYED: Tue Nov 17 18:03:12 2026
NAMESPACE: kube-system
STATUS: deployed
REVISION: 5
DESCRIPTION: Upgrade complete

It is the deployment that fails, not Helm. The rollout (the replacement of the Pods of the old version by those of the new one) does not complete, and the new agents restart in a loop:

Terminal window
kubectl -n kube-system rollout status ds/cilium --timeout=90s
kubectl -n kube-system get pods -l k8s-app=cilium -o wide
Waiting for daemon set "cilium" rollout to finish: 2 out of 3 new pods have been updated...
error: timed out waiting for the condition
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cilium-5rxzk 0/1 CrashLoopBackOff 3 (36s ago) 90s 10.10.50.14 net-cp.lab <none> <none>
cilium-l984p 1/1 Running 0 2m53s 10.10.50.15 net-w1.lab <none> <none>
cilium-wlj9k 0/1 CrashLoopBackOff 3 (42s ago) 90s 10.10.50.16 net-w2.lab <none> <none>

Kubernetes replaced the agents of net-cp and net-w2, and both new ones crash. It has not touched the one on net-w1, the old agent, still healthy. Only that node keeps a running agent.

To read the cause, you need the log of the crashing Pod, and of the previous container (--previous), since the current container has just restarted:

Terminal window
kubectl -n kube-system logs cilium-wlj9k -c cilium-agent --previous --tail=60 | grep -iE 'level=(error|fatal)'
time=2026-11-17T18:03:59.673089683Z level=error msg="Invoke failed" error="egress gateway requires --enable-ipv4-masquerade=\"true\" and --enable-bpf-masquerade=\"true\"" function="cmd.configureAPIServer (cmd/cells.go:399)"
time=2026-11-17T18:04:01.674214372Z level=fatal msg="unable to run agent: failed to start: failed to populate object graph: egress gateway requires --enable-ipv4-masquerade=\"true\" and --enable-bpf-masquerade=\"true\"" subsys=daemon

The message names two options, --enable-ipv4-masquerade and --enable-bpf-masquerade. IPv4 masquerade was already active, as Masquerading: IPTables [IPv4: Enabled showed. The one that is missing is BPF masquerade, set by bpf.masquerade.

A trap lies in wait when reading: kubectl logs ds/cilium reads a single Pod, sometimes the old healthy agent, and then shows no error. You have to name the Pod that crashes.

Which command enables the gateway correctly?

Ask for both settings in the same command. It also repairs the broken state: run on the failing cluster, it restored it without deleting anything.

Terminal window
sudo helm --kubeconfig /etc/kubernetes/admin.conf upgrade cilium cilium/cilium \
-n kube-system --version 1.20.5 --reuse-values \
--set egressGateway.enabled=true --set bpf.masquerade=true
kubectl -n kube-system rollout status ds/cilium --timeout=300s
Release "cilium" has been upgraded. Happy Helming!
NAME: cilium
LAST DEPLOYED: Tue Nov 17 18:04:45 2026
NAMESPACE: kube-system
STATUS: deployed
REVISION: 6
DESCRIPTION: Upgrade complete
Waiting for daemon set "cilium" rollout to finish: 1 of 3 updated pods are available...
Waiting for daemon set "cilium" rollout to finish: 2 of 3 updated pods are available...
daemon set "cilium" successfully rolled out

The Cilium documentation asks you to restart the operator too (the cilium-operator Deployment, the Cilium component that works at the scale of the cluster rather than node by node) after enabling the feature. Restart it once the rollout of the agents is done:

Terminal window
kubectl -n kube-system rollout restart deploy/cilium-operator
kubectl -n kube-system rollout status deploy/cilium-operator --timeout=180s

Then check that masquerade has switched to BPF and that the resource definition of the policy exists:

Terminal window
kubectl -n kube-system exec ds/cilium -c cilium-agent -- cilium status | grep -E 'Masquerading|KubeProxyReplacement'
kubectl get crd ciliumegressgatewaypolicies.cilium.io
KubeProxyReplacement: True [enp1s0 10.10.50.14 fe80::5054:8bff:fed2:13 (Direct Routing)]
Masquerading: BPF [enp1s0] 10.244.2.0/24 [IPv4: Enabled, IPv6: Disabled]
NAME SCOPE VERSIONS CREATED AT
ciliumegressgatewaypolicies.cilium.io Cluster v2(storage) 2026-11-17T17:58:38Z

Masquerading is now BPF, and the ciliumegressgatewaypolicies.cilium.io definition exists, in version v2. It is not attached to a namespace: an egress policy is a cluster resource. Its presence alone does not prove that the gateway is active: Helm leaves it in place if you disable the feature (see the troubleshooting section). The cilium-config ConfigMap also carries the feature: in 1.20.5, its key is enable-egress-gateway (kubectl -n kube-system get configmap cilium-config -o jsonpath='{.data.enable-egress-gateway}' reads it; the value was not captured here).

Enabling the feature changes nothing as long as no policy exists. The Pod that will be selected still leaves with the address of its node:

Terminal window
kubectl -n egress-demo exec sortie-controlee -- wget -qO- -T 5 http://10.10.50.1:8090/bpf-masquerade-sans-politique
source vue par la destination : 10.10.50.15

How do you designate the exit node and write the policy?

You need two things: a node designated by a label, and a CiliumEgressGatewayPolicy that says which Pods leave through this node. The label name is free. Here, egress-gateway=true goes on net-w2.lab, the node whose address the destination will see:

Terminal window
kubectl label node net-w2.lab egress-gateway=true --overwrite
node/net-w2.lab labeled

The policy targets the Pods by label, the destination by address, and the node by its label. Here is the one from the demonstration:

apiVersion: cilium.io/v2
kind: CiliumEgressGatewayPolicy
metadata:
name: sortie-par-net-w2
spec:
selectors:
- podSelector:
matchLabels:
app: sortie-controlee
io.kubernetes.pod.namespace: egress-demo
destinationCIDRs:
- 10.10.50.1/32
egressGateway:
nodeSelector:
matchLabels:
egress-gateway: "true"
interface: enp1s0

Each field has a role:

  • selectors lists the Pods concerned. podSelector.matchLabels combines the Pod label (app: sortie-controlee) and the namespace, designated by the special label io.kubernetes.pod.namespace. Without the latter, a Pod with the same label in another namespace would be selected too. To select every Pod of a namespace, you keep only this namespace label; the Cilium documentation allows it, but this lesson did not test it.
  • destinationCIDRs limits the policy to the listed destinations, here a single machine (/32). The rest of the Pod's traffic leaves normally.
  • egressGateway.nodeSelector designates the exit node by its labels. If several nodes match, the Cilium documentation states that the first one in the alphabetical order of their names is kept: a single node serves as the gateway for the policy. The egressGateways field, a list, spreads the Pods across several gateways, but each Pod goes through only one: it is not a failover in case of failure. The demonstration did not test it. The text "true" is quoted: a label is always a string.
  • egressGateway.interface names the network card of the exit node through which the traffic leaves, enp1s0 on the demonstration VMs. On your nodes, it may have another name. This field is optional: without interface or egressIP, Cilium takes the interface of the default route and its first IPv4 address. The egressIP and interface properties cannot be given together: the documentation says the policy is then ignored.

Apply the policy, then list it:

Terminal window
kubectl apply -f politique.yaml
kubectl get ciliumegressgatewaypolicies
ciliumegressgatewaypolicy.cilium.io/sortie-par-net-w2 created
NAME AGE
sortie-par-net-w2 0s

How do you prove the Pod leaves through the gateway?

The proof is taken on the destination side: you look at the address the witness server receives, not at what the Pod believes it sends. The diagram shows the situation. Follow the two paths that start from net-w1. The thick line is that of the selected Pod: Cilium sends it to the gateway node, which makes it leave with its own address. The dotted line is that of the non-selected Pod, which leaves as before, with the address of its node.

Two Pods on node net-w1, address 10.10.50.15. The Pod selected by the policy (app=sortie-controlee) is sent to the gateway node net-w2, whose address is 10.10.50.16; the server outside the cluster then sees the source 10.10.50.16. The non-selected Pod (app=autre) leaves directly through net-w1; the server sees the source 10.10.50.15, the address of net-w1.Selected Podapp=sortie-controleeOther Podapp=autreTraffic leaves hereaddress 10.10.50.16 sent to the gateway      Server outside the cluster     10.10.50.1 source seen: 10.10.50.15  source seen: 10.10.50.16 Node net-w1 (10.10.50.15)Gateway nodenet-w2
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

Send a request from each Pod, with a different path to find them in the log:

Terminal window
kubectl -n egress-demo exec sortie-controlee -- wget -qO- -T 5 http://10.10.50.1:8090/vise
kubectl -n egress-demo exec autre -- wget -qO- -T 5 http://10.10.50.1:8090/non-vise
source vue par la destination : 10.10.50.16
source vue par la destination : 10.10.50.15

The selected Pod arrives with 10.10.50.16, the address of net-w2, the gateway. The autre Pod, on the same node net-w1 but without the selected label, still arrives with 10.10.50.15. The policy therefore applies Pod by Pod, not node by node. The witness log confirms both lines, with their paths:

2026-11-17T19:02:11 source=10.10.50.16 chemin=/vise
2026-11-17T19:02:12 source=10.10.50.15 chemin=/non-vise

How do you read the BPF egress table?

Cilium translates the policy into a BPF table: a data structure that each agent loads into the kernel of its node, and that Cilium's network program consults for every packet. The cilium-dbg bpf egress list command displays it. It runs in the cilium-agent container of the Cilium Pod of a specific node, and the table does not have the same content everywhere. First find the Cilium Pod of each node (its names change at every restart: use those of your cluster):

Terminal window
kubectl -n kube-system get pods -l k8s-app=cilium --field-selector spec.nodeName=net-w1.lab -o name

In the demonstration, the Cilium Pod of net-w1 is called cilium-l984p, and that of the net-w2 gateway is called cilium-kxkp8. The latter had another name, cilium-wlj9k, in the section on the masquerade trap: the tables below were captured at another time. On the selected Pod's node, the table is:

Terminal window
kubectl -n kube-system exec pod/cilium-l984p -c cilium-agent -- cilium-dbg bpf egress list
Source IP Destination CIDR Egress IP Gateway IP Egress Ifindex
10.244.1.115 10.10.50.1/32 0.0.0.0 10.10.50.16 0

On the gateway, the table is:

Terminal window
kubectl -n kube-system exec pod/cilium-kxkp8 -c cilium-agent -- cilium-dbg bpf egress list
Source IP Destination CIDR Egress IP Gateway IP Egress Ifindex
10.244.1.115 10.10.50.1/32 10.10.50.16 10.10.50.16 2

Here are the columns, one by one:

  • Source IP is the address of the selected Pod (10.244.1.115), not that of the node. The autre Pod does not appear: no rule concerns it.
  • Destination CIDR repeats destinationCIDRs from the policy.
  • Gateway IP is the address of the exit node, the same everywhere (10.10.50.16).
  • Egress IP and Egress Ifindex are only filled in on the gateway: the source address to write (10.10.50.16) and the number of the exit interface. On the Pod's node, they are 0.0.0.0 and 0: that node only knows whom to send the traffic to.

Do not take Egress IP at 0.0.0.0 for a failure: the Cilium documentation shows the same value on every agent except the gateway's. To diagnose, look at the Gateway IP column, which must carry the address of the exit node.

What happens when no node matches?

If the label of the exit node disappears, the policy finds no gateway anymore. The selected traffic is not sent back out by the Pod's node: it is dropped. You trigger this by removing the label (the trailing dash deletes it):

Terminal window
kubectl label node net-w2.lab egress-gateway-
kubectl -n egress-demo exec sortie-controlee -- wget -qO- -T 5 http://10.10.50.1:8090/passerelle-retiree
kubectl -n egress-demo exec autre -- wget -qO- -T 5 http://10.10.50.1:8090/non-vise-2
node/net-w2.lab unlabeled
wget: download timed out
command terminated with exit code 1
source vue par la destination : 10.10.50.15

The selected Pod no longer gets an answer (the -T 5 delay expires), while the autre Pod still answers. The witness log holds no line for /passerelle-retiree: the packet never arrived, not even with the address of net-w1. The Cilium documentation says the same thing: without a matching node, the traffic is dropped. This behavior prevents a Pod from leaving through an unauthorized address, at the price of an outage.

You put the label back, and the exit resumes without touching the policy:

Terminal window
kubectl label node net-w2.lab egress-gateway=true --overwrite
kubectl -n egress-demo exec sortie-controlee -- wget -qO- -T 5 http://10.10.50.1:8090/passerelle-revenue
node/net-w2.lab labeled
source vue par la destination : 10.10.50.16

The Cilium documentation also states that changing the exit node cuts the connections in progress: avoid moving the gateway during a transfer.

What are the limits of the egress gateway?

It does not combine with everything. These limits come from the Cilium 1.20 documentation; the demonstration did not test them.

  • The feature is incompatible with ClusterMesh, the interconnection of several Cilium clusters. The exit node must be in the same cluster as the Pod.
  • CiliumEndpointSlice and the kvstore identity mode, already mentioned in the settings, are also incompatible.
  • The gateway of a policy is a single point of passage: one node serves, and changing that node cuts the connections in progress. The documentation describes no automatic failover if that node goes down; the test in this lesson only shows that the selected traffic is dropped when no node matches.
  • With Istio in ambient mode, the gateway requires bpf.masquerade=true, and the Istio 1.32 documentation says that ambient mode does not support it (the Pods' health probes break). This is why the training runs Istio on a separate cluster: see the lesson Gateway API over HTTPS with cert-manager and the one on Cilium.
  • The Cilium documentation gives no maturity level for the feature, neither stable nor beta: do not assume one.

Troubleshooting

Start with kubectl -n kube-system get pods -l k8s-app=cilium: if an agent is in CrashLoopBackOff, read its previous log before anything else.

SymptomLikely causeSolution
helm upgrade answers "Upgrade complete", but rollout status ds/cilium times out and cilium-… Pods are in CrashLoopBackOffegressGateway.enabled=true enabled without bpf.masquerade=trueRead kubectl -n kube-system logs <pod> -c cilium-agent --previous: the message cites --enable-bpf-masquerade. Rerun the helm upgrade with --set egressGateway.enabled=true --set bpf.masquerade=true
kubectl logs ds/cilium shows no error while agents crashThe command reads a single Pod, sometimes the old agent that is still healthyName the Pod that crashes (STATUS column of get pods) and add --previous
The selected Pod still leaves with the address of its nodeThe policy does not select it: Pod label, namespace (io.kubernetes.pod.namespace) or destination outside destinationCIDRs. Case not tested in the labkubectl get pod --show-labels, compare with selectors, then read cilium-dbg bpf egress list: the Pod's address must appear in it
The selected Pod gets no answer at all (timeout) and nothing appears in the witness logNo node carries the label of nodeSelector: the traffic is droppedkubectl get nodes --show-labels, then kubectl label node <node> egress-gateway=true
kubectl get crd ciliumegressgatewaypolicies.cilium.io answers NotFoundThe feature is not enabled, or the rollout is not finishedCheck Masquerading: BPF in cilium status, wait for the rollout, then restart the operator. The converse is false: the definition being present does not prove the gateway is active, because disabling egressGateway.enabled through Helm does not remove it (the operator creates it on activation and does not remove it, a finding from the lab)
The destination sees an address that is neither that of the Pod's node nor that of the expected gatewayThe card named in interface is not the one on the wanted network. Case not tested in the labip -br link on the gateway, fix interface in the policy

Put it into practice

The guided lab starts from a three-node Cilium cluster without kube-proxy and a witness server placed outside the cluster, which answers with the source address it sees. You must enable the egress gateway with the BPF masquerade it requires, designate net-w2.lab as the exit node, and write a CiliumEgressGatewayPolicy that selects only the sortie-controlee Pod of the egress-demo namespace. The validation checks the Cilium configuration and the policy, then compares two Pods: the witness must see sortie-controlee arrive from net-w2.lab and autre, on the same node, still arrive from net-w1.lab.

Outside the lab, redo the walkthrough from start to finish on a three-node Cilium cluster, with your own witness server. You have succeeded when these four checks hold:

  1. cilium status displays Masquerading: BPF, and the ciliumegressgatewaypolicies.cilium.io definition exists.
  2. The witness log shows the address of the exit node for the selected Pod, and the address of its own node for a non-selected Pod placed on the same node.
  3. cilium-dbg bpf egress list displays the address of the selected Pod and the Gateway IP of the gateway, on the Pod's node as well as on the gateway.
  4. Once the label is removed from the exit node, the request of the selected Pod times out and the log holds no line for it. Once the label is put back, the exit resumes.

When you have finished, clean up: the policy, the test namespace and the node label. The egressGateway.enabled and bpf.masquerade settings stay active in Cilium, and the ciliumegressgatewaypolicies.cilium.io definition stays listed by kubectl get crd. Also stop the witness server.

Terminal window
kubectl delete ciliumegressgatewaypolicy sortie-par-net-w2
kubectl delete namespace egress-demo
kubectl label node net-w2.lab egress-gateway-

The module's challenge, to do alone and without hints, has its own page: Repair and audit the Cilium network.

Key points

  • Without a policy, the destination sees the address of the Pod's node, which changes when the Pod changes node.
  • The Cilium egress gateway requires kubeProxyReplacement=true, egressGateway.enabled=true and bpf.masquerade=true; the documentation adds identities in crd mode (identity-allocation-mode in cilium-config).
  • helm upgrade --reuse-values --set egressGateway.enabled=true without bpf.masquerade=true ends with "Upgrade complete", then the agents crash: the message is read with kubectl logs <pod> -c cilium-agent --previous. You check the activation with Masquerading: BPF in cilium status, and the ciliumegressgatewaypolicies.cilium.io definition must exist. On its own it proves nothing: Helm leaves it in place when you disable the feature.
  • A CiliumEgressGatewayPolicy (cilium.io/v2, no namespace) designates the Pods (podSelector and namespace), the destination (destinationCIDRs) and the exit node (nodeSelector, and interface, optional).
  • The proof is taken on the destination side: the selected Pod arrives with the gateway address, a non-selected Pod on the same node keeps that of its node.
  • cilium-dbg bpf egress list shows the selected Pod and the gateway everywhere, but Egress IP and Egress Ifindex are only filled in on the gateway.
  • Without a matching node, the selected traffic is dropped (timeout, nothing in the witness log), then it resumes when the label comes back.
  • A single node serves as the gateway per policy (the first by alphabetical order of names if several match): it is a single point of passage, with no documented failover. The feature is incompatible with ClusterMesh and with Istio ambient mode.

Knowledge check

The questions cover the address the destination sees, the activation failure without bpf.masquerade, how the policy is written and how to read the BPF table.

Knowledge check

Check what you have learned with this interactive quiz

8 questions
8 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer