A Pod calls an API that checks source IPs The payments Pod sends HTTPS to a partner API. The partner only accepts connections from IP addresses on its allowlist, so you must tell them which IP to allow.
The Pod has IP 10.244.1.7, but that address is private to the cluster. The question of this lesson is which address actually arrives at the partner.
The node rewrites the Pod IP to its own IP When a packet leaves for a destination outside the cluster, most CNI setups masquerade it: source NAT (SNAT) replaces the Pod IP with the node IP. Replies come back to the node, which reverses the translation.
Pod IPs often come from an overlay range the rest of the network cannot route back to, so SNAT is what makes the reply possible. The exact rules depend on the CNI and cloud (for example ip-masq-agent or the cloud CNI settings).
Key idea Inside the cluster, Pods see each other's real Pod IPs. Outside, they usually see the node IP.
A private node goes out through the cloud NAT gateway Nodes in a private subnet have no public IP. Their route to the internet goes through a NAT gateway, which translates the source once more, this time to its own public IP.
The partner therefore sees 203.0.113.10, the NAT gateway address. That is the IP you give them for the allowlist.
Key idea Give partners the NAT gateway's public IPs, and keep those IPs fixed (a reserved or elastic IP) so the allowlist does not break.
Every workload shares the same source IP All Pods on all nodes, and often other VMs in the VPC, leave through the same NAT gateway. To the partner, a compromised Pod in another namespace looks exactly like payments.
Without a NAT gateway it gets worse: if nodes have public IPs, the source changes whenever the autoscaler adds or replaces a node, and the allowlist goes stale.
Watch out An IP allowlist on the far side trusts the whole cluster. Controls on your side decide which Pods may actually go out.
Start from default-deny egress A NetworkPolicy with an empty podSelector, policyTypes: [Egress] and no egress rules blocks all outgoing traffic from every Pod in the namespace.
The CNI enforces it on the Pod side, before any SNAT, so the policy sees the real Pod IP. As soon as it applies, even DNS lookups fail.
Key idea Apply default-deny egress together with the allow rules in the next steps, or names stop resolving right away.
Allow DNS to kube-dns on port 53 Add an egress rule to Pods labeled k8s-app=kube-dns in namespace kube-system (namespaceSelector kubernetes.io/metadata.name: kube-system), on port 53 for both UDP and TCP. Large answers fall back to TCP.
If the cluster runs a node-local DNS cache, the Pod talks to a link-local address on the node instead. Allow that address too, or lookups still time out.
Open the partner by CIDR, because that is all NetworkPolicy has Add an egress rule with ipBlock cidr 198.51.100.0/24 on TCP 443. Now payments reaches the partner, and nothing else outside the cluster.
NetworkPolicy matches only Pods, namespaces and IP blocks. It has no field for a hostname. If api.partner.example sits behind a CDN whose IPs change, a CIDR rule breaks or must be far too wide.
Watch out Use ipBlock.except to cut out ranges you never want, such as the cloud metadata address 169.254.169.254.
Allowing by hostname needs a CNI extension Some CNIs add their own policy types that allow by name. In Cilium, a CiliumNetworkPolicy with toFQDNs matchName: api.partner.example allows only the IPs that name resolved to.
This works by watching DNS answers. The policy must also send DNS through the Cilium DNS proxy (a dns rule on port 53), so the agent learns which IPs belong to the name and opens them for that Pod.
Key idea FQDN rules are not part of the Kubernetes API. Each CNI has its own CRD, and the rule only works if the Pod resolves the name through the cluster DNS path.
An egress gateway gives selected Pods a fixed source IP An egress gateway sends traffic from selected Pods through chosen gateway nodes. In Cilium, a CiliumEgressGatewayPolicy selects Pods and destination CIDRs, and the gateway node SNATs them to a dedicated egress IP. It needs BPF masquerading and kube-proxy replacement.
A mesh does it at L7: Istio with outboundTrafficPolicy REGISTRY_ONLY only lets sidecars reach hosts declared in a ServiceEntry, and routing them through an egress gateway gives one exit point to watch.
Key idea Now the partner can allowlist only the payments exit IP, not the whole cluster. A sidecar can be bypassed, so pair mesh egress rules with a NetworkPolicy.
Watch for egress you did not plan A blocked egress attempt is a silent drop, so the app only sees a timeout. A Pod that suddenly calls an unknown host can be a misconfiguration or a compromised container.
Flow logs show both: CNI tools such as Hubble list dropped and allowed flows per Pod, and NAT gateway or VPC flow logs show what left the network.
Watch out Alert on egress drops and on new external destinations, and check these logs first when an outbound call starts timing out.
Know your exit IP, and allow only what must leave By default a Pod's traffic leaves with the node IP, then the NAT gateway IP, and that shared address is what outside allowlists see.
Lock it down from your side: default-deny egress, allow DNS, allow specific CIDRs, or hostnames through a CNI extension. Use an egress gateway when a partner needs a fixed IP for just one workload.
Summary Run curl https://ifconfig.me from a Pod to see the source IP the outside world actually gets.