Interview Prep/Kubernetes/Services, DNS, Ingress and NetworkPolicy

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.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Services, DNS, Ingress and NetworkPolicy