You run a Kubernetes cluster shared by three product teams. Each team has its own namespace. By default, every pod can reach every other pod across every namespace, can dial any external IP, and the only signal you have when something goes wrong is the security team asking why the staging database is reachable from the marketing site’s frontend pod. NetworkPolicy is the in-cluster firewall and it ships with Kubernetes — the API is universal, the enforcement is your CNI’s problem. This article is the working set of patterns we put in every multi-tenant cluster we operate.
What’s happening
Kubernetes ships with a permissive default. A pod in team-a can connect() to a pod in team-b, to a Service in kube-system, to a database VM outside the cluster, to anywhere on the internet. NetworkPolicy resources change that — but only if your CNI enforces them. Calico, Cilium, Antrea, kube-router all enforce. Flannel by itself does not (you need flannel + network-policy-controller for that). The first job in a multi-tenant cluster is confirming the CNI actually enforces policy — apply a deny-all, watch a curl fail. The second job is the four patterns below: cluster-wide default-deny, namespace isolation, egress allow-lists, and access to platform services (DNS, metrics, ingress).
How to verify
Apply a deny-all in a test namespace and confirm enforcement:
kubectl create ns netpol-check
kubectl run web --image=nginx -n netpol-check
kubectl expose pod web --port=80 -n netpol-check
kubectl apply -n netpol-check -f - <<'YAML'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: deny-all }
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
YAML
kubectl run -n netpol-check --rm -it --restart=Never \
--image=curlimages/curl curl-test -- curl -m 3 web
# Should time out. If it returns the nginx page, your CNI doesn't enforce.
The fix
Four patterns. Apply them in order, audit after each one.
Pattern 1 — Cluster-wide default-deny egress
Most teams reach for default-deny ingress first. Default-deny egress is the higher-value control because it prevents an exfiltration path you didn’t think about. Apply this in every tenant namespace:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-egress
namespace: team-a
spec:
podSelector: {}
policyTypes: [Egress]
Then layer allow rules on top. The compromise pod that doesn’t have a working egress path can’t talk to its C2 server. You will discover broken egress paths — that’s the point.
Pattern 2 — DNS allow
A default-deny egress namespace can’t resolve names. Allow CoreDNS:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns
namespace: team-a
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
Label kube-system if your CNI/cluster doesn’t auto-label it. Note: NetworkPolicies are additive — adding this one to the namespace gives DNS on top of whatever else is allowed.
Pattern 3 — Namespace isolation (deny cross-namespace ingress)
Each tenant namespace gets a policy that says “ingress is only from inside this namespace, plus ingress-nginx for HTTP, plus the platform monitoring agents”:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: namespace-isolation
namespace: team-a
spec:
podSelector: {}
policyTypes: [Ingress]
ingress:
- from:
- podSelector: {}
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: monitoring
podSelector:
matchLabels:
app.kubernetes.io/name: prometheus
Cross-namespace ingress is now denied by default. If team-b legitimately needs to call into team-a, that’s an explicit, reviewable NetworkPolicy — not the silent default.
Pattern 4 — Egress allow-list per workload class
Don’t write one giant egress allow for the namespace. Group workloads by their egress needs — “needs to call third-party API X”, “needs to reach the managed database VLAN”, “needs to publish to a queue” — and label the pods accordingly. Then write per-label policies:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: egress-stripe-api
namespace: team-a
spec:
podSelector:
matchLabels:
egress.acme.io/stripe: "true"
policyTypes: [Egress]
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
ports:
- protocol: TCP
port: 443
The egress here is to the public internet only — RFC1918 ranges are excluded. Pair it with FQDN policies (CalicoNetworkPolicy or CiliumNetworkPolicy with toFQDNs) when you can; standard NetworkPolicy is CIDR-only.
For Cilium, the FQDN-scoped equivalent:
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: egress-stripe-fqdn
namespace: team-a
spec:
endpointSelector:
matchLabels:
egress.acme.io/stripe: "true"
egress:
- toFQDNs:
- matchName: api.stripe.com
toPorts:
- ports:
- { port: "443", protocol: TCP }
- toEndpoints:
- matchLabels:
"k8s:io.kubernetes.pod.namespace": kube-system
"k8s:k8s-app": kube-dns
toPorts:
- ports:
- { port: "53", protocol: UDP }
rules:
dns:
- { matchPattern: "*" }
Audit and ratchet
After applying, audit drops. Calico: calicoctl get globalnetworkpolicy -o yaml plus log-action policies for specific selectors. Cilium: hubble observe --verdict DROPPED --follow. Standard NetworkPolicy with no audit hooks is the weakest of the three — if you can move to Calico or Cilium policies you get observability you can’t get from the upstream API alone.
The ratchet pattern: start with default-deny + DNS + intra-namespace + ingress-nginx, deploy real workloads, watch the drops Hubble or Calico flow logs report, add explicit allow rules for each legitimate flow. Two weeks in, you have an allow-list that describes what the workload actually does, and a drop log that catches anything new. This is the only sustainable shape for multi-tenant network policy — write rules at the speed of discovery, not all-up at design time.
We run multi-tenant Kubernetes clusters on our managed cloud compute under Managed Cloud Ops with policy templating, drop-rate alerting, and quarterly rule audits in our monitoring plane — start a scoping call if you want help getting from “open cluster” to “default-deny with explicit allows.”