Interview Prep/Kubernetes/Services, Networking, Ingress & Gateway API

Why does a NetworkPolicy with `egress` rules often break DNS, and how do you fix it?

AdvancedConceptServices, Networking, Ingress & Gateway API
Answer

Once egress is restricted, the Pod can no longer reach CoreDNS on port 53 UDP/TCP. Add an explicit rule allowing egress to the kube-system namespace's k8s-app=kube-dns Pods.

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 }]
All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Services, Networking, Ingress & Gateway API