☸️ Kubernetes: Fix a NetworkPolicy Silently Blocking DNS Egress
With no NetworkPolicy selecting a Pod, Kubernetes allows all egress traffic by default – but the moment any NetworkPolicy’s podSelector matches that Pod, its egress switches to default-deny for everything not explicitly listed in an egress rule. DNS lookups (to kube-dns or CoreDNS, almost always on port 53 UDP and TCP) are just another egress connection that has to be allowed like any other destination, and it’s easy to write a policy listing exactly the application’s intended destinations – a database, an external API – while never thinking to list DNS, since application code doesn’t usually think of a hostname lookup as ‘a destination it talks to’ even though literally every outbound call that uses a hostname depends on it.
🔎 The Problem
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: payments-egress
spec:
podSelector:
matchLabels: { app: payments }
policyTypes: [Egress]
egress:
- to: [{ podSelector: { matchLabels: { app: postgres } } }]
ports: [{ protocol: TCP, port: 5432 }]
# no rule allowing port 53 to kube-dns/CoreDNS anywhere
# -> every hostname lookup from this pod now times out silently
✅ The Fix
- Add an explicit egress rule allowing both UDP and TCP port 53 to the cluster’s actual DNS pods (confirm the exact labels with kubectl get pods -n kube-system -l k8s-app=kube-dns -o wide, since the namespace and labels can differ by provider) in every NetworkPolicy that restricts egress.
- Treat DNS egress as a mandatory line in a reusable policy template or admission check for the team, rather than something each new NetworkPolicy author has to remember independently – a missing DNS rule is one of the easiest lines to forget precisely because it’s rarely a direct dependency of the application’s own code.
- After applying any egress-restricting NetworkPolicy, test with kubectl exec <pod> — nslookup <service> before assuming the policy is complete, since a DNS failure can otherwise look identical to a broader, harder-to-diagnose application bug.
🚨 Why This Is Dangerous
A Pod that’s lost DNS resolution can still pass a liveness check that only pings a hardcoded IP, so the cluster reports it as perfectly healthy while every outbound call relying on a hostname silently times out – a failure mode that looks like ‘the app is broken’ rather than ‘this pod can no longer resolve a single name.’
An egress policy that never mentions DNS isn’t neutral about DNS – the moment it selects your pod, it’s blocking DNS too, by omission rather than by name.




