How do you design default-deny NetworkPolicies without breaking DNS?
IntermediateProductionKubernetes & Service Networking in Production
Answer
Apply a default-deny for ingress and egress in each namespace, then allow explicitly: DNS to kube-dns on UDP and TCP 53, traffic from ingress controller namespace, app-to-app flows, and egress to required external CIDRs.
egress:
- to:
- namespaceSelector: {matchLabels: {kubernetes.io/metadata.name: kube-system}}
podSelector: {matchLabels: {k8s-app: kube-dns}}
ports: [{protocol: UDP, port: 53}, {protocol: TCP, port: 53}]
Roll out in audit mode first (Cilium policy audit, Calico staged policies).
More on Kubernetes & Service Networking in Production
How do you expose an application on Kubernetes to the internet in production?BeginnerALB IP mode versus instance mode on EKS: which should you use?IntermediateHow do you achieve graceful pod shutdown with no dropped requests?AdvancedHow do readiness, liveness and startup probes interact with traffic?BeginnerHow do you debug "pod cannot reach service" in Kubernetes?AdvancedHow do you scale CoreDNS and avoid DNS becoming an outage source?Advanced