By default every pod in a Kubernetes cluster can reach every other pod. Network policies, enforced by the CNI plugin (Calico, Cilium, or the cloud provider's own), turn that into an allow-list. A namespace-wide default deny for ingress and egress, followed by narrow policies per service, means a compromised pod can reach only what that service was meant to reach.
- Detect
- Analyze
- Resolve
When to use it
- Any multi-tenant or multi-team cluster
- Clusters running internet-facing services
- Compliance scopes that need network segmentation inside the cluster
When to avoid it
- Clusters whose CNI does not enforce policies: the objects are accepted but do nothing
How traffic flows
- Apply a policy that selects all pods and allows nothing. All ingress and egress in the namespace stops.
- Allow DNS egress to kube-dns, or nothing else will work.
- Add one ingress policy per service naming exactly which pods or namespaces may connect, and on which port.
- Add matching egress rules for outbound calls, including to databases and external APIs.
Configuration examples
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: shop
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns
namespace: shop
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 }apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: db-from-api
namespace: shop
spec:
podSelector:
matchLabels: { app: db }
policyTypes: [Ingress]
ingress:
- from:
- podSelector:
matchLabels: { app: api }
ports:
- { protocol: TCP, port: 5432 }Examples are starting points. Review provider limits, names and versions for your environment before applying.
What to monitor
| Signal | Why it matters |
|---|---|
| Denied flows by source and destination | Separates a missing rule from a pod that should never connect. |
| Namespaces without a default-deny policy | Every new namespace starts wide open. |
| Policy changes | A broad allow added during an incident often stays forever. |
Common failure modes
Forgot to allow DNS
Everything in the namespace fails name resolution after default-deny.
Pulse sees DNS timeouts spike right after the policy is applied and names the missing rule.
Wide-open namespace
A new team namespace has no policies at all.
Sentinel lists namespaces without default-deny in its daily audit.