A NetworkPolicy allows traffic from namespace `monitoring` with `namespaceSelector: {matchLabels: {name: monitoring}}`, but Prometheus scrapes are still blocked.
IntermediateTroubleshootingServices, DNS, Ingress and NetworkPolicy
Answer
Likely causes → The namespace has no name: monitoring label. Namespaces automatically get kubernetes.io/metadata.name: <name>, not name.
Diagnose →
kubectl get ns monitoring --show-labels
Fix → Use the automatic label:
- namespaceSelector:
matchLabels: {kubernetes.io/metadata.name: monitoring}
Also allow the metrics port in ports.
Prevent → Always use kubernetes.io/metadata.name for namespace selection; it cannot be forgotten or spoofed by tenants editing labels.
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