Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
A Kubernetes NetworkPolicy controls which pods may talk to which. Without one, every pod in the cluster can reach every other pod, on every port.

What Are Kubernetes Network Policies?
By default, a Kubernetes cluster is a flat network. Every pod can open a connection to every other pod, in every namespace, on every port, regardless of what the two workloads have to do with each other. A NetworkPolicy is the resource that changes that, specifying which traffic is permitted to and from a selected group of pods. For an attacker who has compromised a single container, the presence or absence of these policies is the difference between a contained incident and free movement across the cluster.
Policies are namespaced and select pods by label. The behaviour catches people out at first because it is allow-list based with a switch: a pod that no policy selects accepts all traffic, and a pod selected by any policy accepts only what that policy and any other policy selecting it permit. Policies are additive—there is no deny rule and no ordering—so the effective permission is the union of every policy that applies.
Each policy declares policyTypes of Ingress, Egress, or both, and omitting egress from a policy that only lists ingress rules leaves outbound traffic entirely unrestricted. Peers are selected by podSelector, namespaceSelector, or ipBlock, with ports and protocols attached.
The standard pattern is to apply a default-deny policy per namespace and then permit what is needed:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: payments
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
With no rules listed, nothing is allowed. You then add policies permitting the application pods to receive traffic from the ingress controller, to reach their database, and to resolve DNS. That last one is the classic first failure: deny egress without allowing UDP and TCP port 53 to the cluster DNS service, and every workload in the namespace stops working in a way that takes an hour to diagnose.
Roll this out namespace by namespace, starting with the least critical. Where your network plugin supports a policy audit or logging mode, use it to observe what would have been dropped before you enforce.
Most teams write ingress rules and stop. Outbound control is what limits an attacker who already has code running inside a pod: command and control, data exfiltration, tool download, and reaching the cloud metadata endpoint described in our entry on the IMDS attack are all egress. Blocking the link-local range 169.254.169.254/32 for pods that do not need instance credentials is a short policy with a large effect.
Kubernetes defines the API; enforcement is the job of the container network interface plugin. Calico, Cilium, Antrea, and the managed network plugins in the major cloud providers all enforce policies. Flannel, in its default configuration, does not—it accepts the resources and silently ignores them, which produces the worst possible outcome: policies that appear to exist and enforce nothing. Confirm enforcement empirically on a new cluster by applying a deny policy and attempting the connection yourself.
Generate policies from observed traffic where your tooling supports it, rather than writing them from an architecture diagram that is already out of date. Keep them in version control beside the workload manifests so a new dependency is added in the same pull request as the code that needs it. Test them in CI against the expected connections, and re-test after a cluster upgrade or a plugin change.
Finally, treat cluster segmentation as one layer within the broader design described in cloud network segmentation. A policy preventing pod-to-pod traffic is worth little if both pods hold cloud credentials that reach the same data through the provider API.
At Privia Security, we validate cluster segmentation by trying to cross it, through our cloud security services.
Every pod can reach every other pod in the cluster, in any namespace, on any port. A single compromised container can scan the whole cluster, reach databases and internal APIs directly, and attempt to exploit anything it finds. That is the default behaviour of Kubernetes, not a misconfiguration, which is why a default-deny policy per namespace is one of the highest-value changes available.
Almost always DNS. A default-deny policy that includes egress blocks resolution against the cluster DNS service, so every outbound connection fails in a confusing way. Add a policy permitting UDP and TCP port 53 to the DNS pods in kube-system before enforcing anything else, then add rules for each legitimate dependency one at a time.
No. Calico, Cilium, Antrea, and the managed plugins from the major cloud providers enforce them. Flannel in its default configuration does not: it accepts the resources and ignores them, so policies appear to exist while enforcing nothing. Verify enforcement empirically on any new cluster by applying a deny rule and testing the connection rather than trusting the documentation.
Only if you need what the mesh adds. Network policies give you layer 3 and 4 control by label, which covers most containment requirements. A mesh adds mutual TLS with cryptographic workload identity, layer 7 authorisation on paths and methods, and detailed traffic telemetry, at a significant operational cost. Start with network policies, and adopt a mesh when a specific requirement justifies it.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.