☸️ The NetworkPolicy That Allowed Exactly What It Said and Nothing Else
The moment a single NetworkPolicy selects a given pod, Kubernetes switches that pod’s networking from ‘allow everything by default’ to ‘deny everything except what’s explicitly allowed’ – which means adding one narrowly-scoped policy (meant only to restrict traffic FROM a specific source) can silently start blocking completely unrelated, previously-working traffic to that same pod from every OTHER source, if that traffic was never explicitly allowed by any policy at all. Nothing about applying the new policy warns that it’s about to change the pod’s default posture this broadly.
🔎 The Problem
# Intent: restrict traffic to the "api" pods so ONLY the "frontend"
# pods can reach them, tightening up an app that used to accept
# traffic from anywhere in the cluster.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: api-allow-frontend
spec:
podSelector:
matchLabels:
app: api
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
# The moment this policy is applied, EVERY ingress connection to "api"
# pods that isn'"'"'t from something matching app: frontend now gets
# blocked - including the monitoring/metrics scraper, the health-check
# probe from a separate namespace, and any other legitimate consumer
# nobody thought to list, none of which were ever mentioned in this
# policy at all.
✅ Fix: Enumerate Every Legitimate Source Before Applying a Restrictive Policy
- Before applying any new Ingress-restricting NetworkPolicy, listing every actual current consumer of the target pods (application traffic, a metrics scraper, health probes from the kubelet or a service mesh, anything in a different namespace) and explicitly allowing each one avoids the silent default-deny side effect for traffic nobody remembered to account for.
- Applying a new policy in a non-production namespace first, then actively testing every known consumer’s connectivity against it before promoting the same manifest to production, catches a missing allow-rule directly rather than discovering it through a production incident once real traffic actually gets blocked.
- kubectl describe networkpolicy combined with a quick check of exactly which pods/namespaces a policy’s podSelector and namespaceSelector actually match (rather than assuming from the YAML alone) confirms the rule is scoped exactly as intended – a label selector that matches more or fewer pods than expected is a common, separate way this same kind of policy goes wrong.
⚠️ Why This Is Easy to Get Wrong the First Time
- NetworkPolicy’s default-deny-once-selected behavior is a deliberate security design choice, but it’s genuinely counterintuitive coming from a namespace where no NetworkPolicy has ever existed before – the very first policy ever applied to a given pod selector is the one most likely to silently break something, specifically because everything was implicitly allowed right up until that moment.
- The blocked traffic often isn’t the main application flow being tested during a policy rollout – it’s a secondary, easy-to-forget consumer (monitoring, health checks, an admin tool in a different namespace) that keeps working fine for a while after the policy is applied, until whatever depends on it eventually notices something’s been silently failing.
The instant a NetworkPolicy touches a pod, everything not explicitly named in some policy is now denied by default – and a policy written to restrict one specific source can just as easily end up restricting every other source nobody thought to mention.





