A NetworkPolicy meant to allow "frontend Pods in namespace web" accidentally allows every Pod in namespace web, or blocks everything. What's wrong with the YAML?
AdvancedTroubleshootingServices, DNS, Ingress and NetworkPolicy
Answer
Likely causes → The difference between one list item with two selectors (AND) and two list items (OR):
# AND: Pods labelled app=frontend IN namespace web
- namespaceSelector: {matchLabels: {kubernetes.io/metadata.name: web}}
podSelector: {matchLabels: {app: frontend}}
# OR: any Pod in namespace web, OR app=frontend Pods in the policy's own namespace
- namespaceSelector: {matchLabels: {kubernetes.io/metadata.name: web}}
- podSelector: {matchLabels: {app: frontend}}
One extra - changes the meaning.
Diagnose →
kubectl describe networkpolicy allow-frontend -n api # describe prints the parsed rules
Fix → Remove the extra dash to combine selectors in one peer.
Prevent → Use the Cilium/Calico policy editor or kubectl describe in review, and add connectivity tests that assert both allowed and denied paths.
More on Services, DNS, Ingress and NetworkPolicy
`curl http://orders.shop.svc.cluster.local` hangs, and `kubectl get endpointslices -l kubernetes.io/service-name=orders` shows `ENDPOINTS <unset>`.BeginnerEndpoints exist, but `curl orders:80` returns `Connection refused`.BeginnerA Service works when you curl the Pod IP but times out on the ClusterIP from every node.IntermediateInside a Pod, `nslookup orders` returns `;; connection timed out; no servers could be reached`.BeginnerCoreDNS Pods are in CrashLoopBackOff with `[FATAL] plugin/loop: Loop (127.0.0.1:41823 -> :53) detected for zone "."`.IntermediateCalls to `api.stripe.com` from Pods are slow, and CoreDNS logs show `api.stripe.com.payments.svc.cluster.local`, `api.stripe.com.svc.cluster.local` … all `NXDOMAIN`.Intermediate