Interview Prep/Real-World Interview/Kubernetes cluster-level

Someone applied a default-deny NetworkPolicy in `prod`; now every pod fails to call other services with "getaddrinfo ENOTFOUND orders" even though the allow rules look right.

BeginnerTroubleshootingKubernetes cluster-level
Answer

Likely causes → The default-deny blocks egress too, including DNS to CoreDNS in kube-system. Your allow rules permit traffic to the service, but the name can't be resolved first.

Diagnose →

kubectl get networkpolicy -n prod
kubectl exec deploy/api -n prod -- nslookup orders
kubectl exec deploy/api -n prod -- nc -vz 10.96.0.10 53

Fix → Add an egress rule allowing DNS:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: allow-dns, namespace: prod }
spec:
  podSelector: {}
  policyTypes: [Egress]
  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 }

Prevent → Ship default-deny and allow-DNS together as one bundle, and test policies in staging with a connectivity check.

All Real-World Interview questions Roadmap: Interview readiness

More on Kubernetes cluster-level