Zero-Trust CiliumNetworkPolicy DNS Blackhole & Rolling Deploy 502s
Prevent default-deny Cilium egress policies from blocking kube-dns:53 and eliminate Kubernetes rolling deployment 502s with preStop graceful drain hooks.
Applying a strict CiliumNetworkPolicy immediately triggers DNS lookup timeouts (i/o timeout to 10.96.0.10:53), and every rolling deployment causes a 3-second burst of HTTP 502 errors.
rate(coredns_dns_requests_total[5m]) == 0 OR increase(ingress_nginx_requests{status="502"}[2m]) > 15In Kubernetes and Cilium, selecting a pod with an egress policy switches that pod to default-deny egress. If you allow egress only to pgbouncer:6432 without explicitly permitting UDP/TCP port 53 to kube-dns, pods cannot resolve service hostnames at all.
During pod termination, kubelet sends SIGTERM to the container IN PARALLEL with kube-proxy / Cilium removing the pod IP from EndpointSlices and eBPF BPF maps across cluster nodes.
If the app immediately closes its listening socket on SIGTERM (preStop=0s), in-flight traffic still routed by nodes whose eBPF maps update 1-4 seconds later hits ECONNREFUSED and returns HTTP 502.
Why does adding a 10-second preStop sleep eliminate HTTP 502s during Kubernetes rolling updates?
- Confirm hubble observe --verdict DROPPED shows zero unintended port-53 drops.
- Run a continuous 100 RPS load test during kubectl rollout restart deploy/checkout-api and verify 0 HTTP 502 responses.
- Ensure terminationGracePeriodSeconds (e.g., 35s) is strictly greater than preStop sleep (10s) plus max in-flight request duration.
Does a Kubernetes namespace provide network isolation by default?
No. By default, every pod in every namespace can communicate with every other pod unless a NetworkPolicy or CiliumNetworkPolicy selects the pod.
Why must both UDP 53 and TCP 53 be allowed for kube-dns?
Standard DNS queries use UDP 53, while large responses (> 512 bytes, DNSSEC, or large headless service SRV records) fall back to TCP 53.
Should my container process also handle SIGTERM gracefully after preStop?
Yes. After preStop completes, the app receives SIGTERM, stops accepting new requests, finishes in-flight requests cleanly, closes DB pools, and exits 0 before SIGKILL.