Skip to main content
Networking & service meshLesson 5 of 11

Traffic Leaving the Cluster (Egress)

A payments Pod calls a partner API that only accepts known source IPs. Follow the packet out of the cluster: Pod → node SNAT → NAT gateway → partner. Then lock egress down with policies and give the traffic a fixed source IP.

Source IP the partner sees?
Egress policynone (all open)
Allowed destinationsanything
Kubernetes clusterpayments PodPod IP 10.244.1.7NodeSNAT · 10.0.1.20NetworkPolicyEgress ruleskube-dnsUDP/TCP 53Egress gatewayFixed source IPCloud NAT GWPublic 203.0.113.10Partner APIIP allowlistUnknown hostUnexpected egressFlow logse.g. Hubble · VPC logsHTTPS
RequestWatchAppears in a later step

What you will learn

  • Why the outside world sees node or NAT IPs, not Pod IPs
  • Default-deny egress, then allow DNS and specific CIDRs
  • Why NetworkPolicy cannot allow a hostname, and what CNIs add
  • How an egress gateway gives a fixed source IP
  • Watching for egress you did not expect

Ways to control egress​

NeedToolMatches onLimits
Block all, open a few pathsNetworkPolicy egressPod and namespace labels, ipBlock CIDRs, portsNo hostnames; enforced only if the CNI supports policies
Allow by hostnameCNI extension, e.g. Cilium toFQDNsDNS names learned from DNS answersCNI-specific CRD; the Pod must resolve through the cluster DNS path
Fixed source IP for some PodsEgress gateway, e.g. Cilium Egress GatewaySelected Pods and destination CIDRsGateway nodes become a dependency; needs specific CNI features
Only declared external hosts, L7 viewService mesh, e.g. Istio REGISTRY_ONLY + ServiceEntry + egress gatewayHostnames, ports, protocolsSidecar or proxy can be bypassed; pair with NetworkPolicy
One public IP for the whole VPCCloud NAT gatewayRoute tableEvery workload shares the IP

Try it yourself​

# Which source IP does the outside world see?
kubectl run egress-test --rm -it --image=curlimages/curl --restart=Never -- curl -s https://ifconfig.me
kubectl get networkpolicy -n <namespace> # POD-SELECTOR and which policies exist
kubectl describe networkpolicy <name> -n <namespace> # Allowing egress traffic: ports and ipBlock
kubectl get pods -n kube-system -l k8s-app=kube-dns --show-labels # Labels the DNS rule must select
kubectl get ciliumnetworkpolicy -A # Cilium: toFQDNs rules
kubectl get ciliumegressgatewaypolicy # Cilium: egress gateway policies (cluster-scoped)
hubble observe --verdict DROPPED --traffic-direction egress # Cilium Hubble: blocked outbound flows
kubectl get serviceentry -A # Istio: declared external hosts

Check yourself

  1. A partner allowlists your NAT gateway IP. Why does that not limit which of your Pods can call them?
  2. You apply default-deny egress and allow 198.51.100.0/24 on port 443. Calls to api.partner.example still fail. What is the likely cause?
  3. The partner API sits behind a CDN with changing IPs, and you want to allow it by name. What do you need?

Further reading: Network Policies · Cilium Egress Gateway · Cilium DNS-based policies · Istio egress gateways · Blocking and Allowing Traffic (NetworkPolicy) · How a Request Travels Inside a VPC