Kubernetes network policies: the low-cost defence most clusters still lack
By default every pod can reach everything. Network policies decide whether a small breach stays small. Why default deny and egress rules matter, and how to introduce them without an outage.
Key takeaways
- Out of the box every pod can reach every other pod and the internet; a network policy turns that into an explicit allow-list.
- Begin with a default-deny policy per namespace, then add back DNS, databases and the services each workload truly needs.
- Egress rules matter most: block admin APIs, cloud metadata endpoints, the internet and other environments for workloads that have no use for them.
- Your CNI (Calico or Cilium, for example) has to enforce the policies, and a pipeline test should prove that forbidden traffic fails.
Out of the box, every pod in a Kubernetes cluster can talk to every other pod, in every namespace, and to anything on the internet. Most teams know this. Far fewer do anything about it, because nothing breaks while the network is wide open. It matters only on the day someone gets a foothold, and on that day it is the one thing that matters.
An attacker’s first step into a system rarely gets them far: a web endpoint that will fetch a URL on their behalf, or a test application with a weak password. What turns a small foothold into a serious incident is the step after: reaching, from that single workload, admin APIs, databases and other environments that should never be reachable from there. A network policy turns that step into a dead end. With automated, AI-driven attackers, that step now takes minutes rather than weeks.
What a network policy really does
A NetworkPolicy is a firewall rule for pods, expressed in labels rather than IP addresses. It defines which pods may receive traffic from where (ingress) and which pods may send traffic to where (egress). Once a single policy selects a pod for a direction, anything not explicitly allowed in that direction is dropped.
Two things catch people out:
- Your network plugin must enforce them. Kubernetes stores the objects, but enforcement is the CNI’s job. Calico and Cilium enforce them; some simple setups quietly ignore them. Check before you depend on it.
- Policies are additive allow-lists. The standard API has no “deny” rule. You get “deny” by selecting a pod and allowing nothing.
Begin with default deny, per namespace
The most valuable single policy is the one that selects every pod in a namespace and allows nothing:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
From there you add back exactly what each workload needs: DNS, its database, the services it calls and the ingress controller in front of it. Every allow rule is small, readable and easy to review, and together the rules become living documentation of how your system communicates.
Egress is where attackers operate
Most teams that use network policies restrict only ingress. That keeps a database away from the internet, but does nothing once an attacker runs code inside a pod. Egress rules decide what that code can reach:
- Admin and management APIs (gateways, brokers, operators, the Kubernetes API itself) should be reachable only from the few pods that manage them.
- Cloud metadata endpoints hand out credentials to anything that asks. Block them for every workload that does not need them.
- The internet. A backend that only talks to internal services has no reason to open connections to arbitrary addresses. Blocking that stops tool downloads and most command-and-control traffic.
- Other environments. Staging should not reach production, and neither should be able to wander into the other’s namespaces.
An open proxy behind a strict egress policy is a nuisance. The same proxy with unrestricted egress is a door to everything the cluster can reach.
Rolling them out without an outage
- Observe first. Tools like Cilium Hubble or Calico flow logs show who really talks to whom. Real traffic always holds a few surprises.
- Label consistently. Policies are only as good as the labels they select. Agree on
app,componentand namespace labels and enforce them in your Helm charts. - Go namespace by namespace, starting with the most exposed workloads: anything internet-facing, anything that fetches URLs, anything that runs user-supplied code.
- Ship policies with the application. Keep them in the same chart as the deployment, so no new service goes live without its rules, and review them like code.
- Test the deny, not only the allow. A pipeline step that tries to reach something forbidden and expects to fail catches a policy that has quietly stopped applying.
- Allow DNS explicitly. It is the classic first outage after default deny.
What network policies will not do
They are one layer, not the whole answer. They do not authenticate anyone, do not encrypt traffic, and cannot tell a legitimate request from a malicious one on an allowed path. Pair them with authentication on every admin API, mutual TLS where it matters, no default credentials, and runtime detection on the nodes. Of all those layers, though, network policies are the cheapest to add and the one most often missing. For the layers above the network, see keeping AI agents in bounds.
FAQ
Are Kubernetes network policies enabled by default?
No. Without any policy, all pods can talk to each other and to the internet. Policies also work only if the cluster’s network plugin enforces them; Calico and Cilium do, while some simple setups quietly ignore them.
What is a default-deny network policy?
A policy that selects every pod in a namespace (an empty podSelector) for both ingress and egress and allows nothing. Everything a workload needs is then added back through small, explicit allow rules.
Why do egress policies matter?
Ingress rules protect a service from outside, but once an attacker runs code in a pod, egress rules decide what that code can reach: admin APIs, cloud metadata credentials, the internet or other environments.
How do I roll out network policies without breaking production?
Observe real traffic first with tools like Cilium Hubble or Calico flow logs, label workloads consistently, roll out namespace by namespace, allow DNS explicitly, and ship the policies in the same Helm chart as the application.
Do you run default deny in your clusters? What made it stick, or what made you roll it back? We would like to hear about it.
