By default, every pod in a Kubernetes cluster can open a connection to every other pod. A default-deny policy applied on its own takes DNS down with it, and the namespace stops working.
A useful baseline is small: a default deny in both directions, a DNS exception, and two or three explicit allows per namespace. Introducing them without an outage takes a method, and so does knowing what they don't cover.
Who this is for: platform engineers adding network segmentation to a cluster that already runs workloads.
What you walk away with: the handful of policies a namespace needs, a rollout order that gives you a rollback at every step, the limits of the NetworkPolicy API, and where cluster-wide policy stands.
The policies, enforcement test and rollout order were run on one cluster (GKE 1.36.4, Dataplane V2) on 17 November 2026. No other CNI plugin was tested, and the cluster-wide section is written from documentation.
First: is anything enforcing them?
The API server accepts NetworkPolicy objects on every cluster. Enforcement is the network plugin's job. The documentation says: "Creating a NetworkPolicy resource without a controller that implements it will have no effect."
No API field tells you whether policies are enforced. Test it in a scratch namespace:
kubectl create namespace np-test
kubectl -n np-test run web --image=nginx --port=80 --expose
kubectl -n np-test wait --for=condition=Ready pod/web --timeout=60s
kubectl -n np-test run probe --rm -it --restart=Never --image=busybox:1.36 \
-- wget -qO- -T 3 http://web
That prints the nginx welcome page. Now deny all ingress and repeat the probe:
kubectl -n np-test apply -f - <<'EOF'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {}
policyTypes: [Ingress]
EOF
kubectl -n np-test run probe --rm -it --restart=Never --image=busybox:1.36 \
-- wget -qO- -T 3 http://web
kubectl delete namespace np-test
A timeout means policies are enforced. A second welcome page means they are decoration, and nothing below will do anything until you change or reconfigure your CNI plugin.
The rules of the model
Four statements from the docs explain most surprises.
- A pod is open until a policy selects it. A pod becomes isolated for a direction when any NetworkPolicy both selects it and lists that direction in
policyTypes. From then on, only what some policy allows gets through. - Policies only add. "Network policies do not conflict; they are additive." There is no deny rule and no ordering. The result is the union of everything allowed.
- Both ends must agree. A connection needs the source pod's egress policy and the destination pod's ingress policy to allow it.
- Replies are implicit. Reply traffic for an allowed connection is allowed. You write rules for who opens the connection.
One more detail: an ingress-isolated pod still accepts connections from its own node. Kubelet health probes therefore keep working under a default deny.
The baseline, policy by policy
Apply these per namespace. The examples use namespace shop.
1. Default deny, both directions
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: shop
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
The empty podSelector selects every pod in the namespace, including ones created later. On its own, this policy breaks everything that uses a hostname.
2. DNS egress, the one everyone forgets
With egress denied, pods cannot reach the cluster DNS, so every lookup fails and applications report errors that look nothing like a network policy problem.
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
Check three things against your own cluster before relying on it:
kubectl -n kube-system get pods -l k8s-app=kube-dns -o wide
kubectl -n kube-system get svc kube-dns -o jsonpath='{.spec.ports}{"\n"}'
- The label.
k8s-app: kube-dnsis the conventional label on CoreDNS pods. Your distribution may use another, or run DNS in a different namespace. - The port. Write the port the DNS pods listen on. If the Service maps port 53 to a different
targetPort, the policy most likely needs the target port, because enforcement usually happens after the Service address is translated. That was confirmed on GKE Dataplane V2 only. - TCP as well as UDP. DNS falls back to TCP for large responses. A UDP-only rule works until a response is too big.
A node-local DNS cache changes this, because queries go to the cache, not the CoreDNS pods. On GKE 1.36.4 with Dataplane V2 the policy above failed: the cache runs as pods labelled k8s-app: node-local-dns, and lookups worked once a second to entry selected that label. A cache listening on a node address probably needs an ipBlock rule instead, since no pod selector matches it. Plugins differ, so test it.
The CoreDNS debugging article covers telling a policy block apart from a DNS fault.
3. Traffic inside the namespace
Whether pods in one namespace may talk to each other freely is a design decision. Allowing it keeps the baseline small:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-same-namespace
namespace: shop
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
ingress:
- from:
- podSelector: {}
egress:
- to:
- podSelector: {}
With this policy the namespace is your unit of isolation, and a compromised pod can reach its neighbours. Without it, you write one policy per connection between workloads, which is more secure and more to maintain. Start with it, and remove it for the namespaces where the data justifies the work.
4. The ingress controller
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-ingress-controller
namespace: shop
spec:
podSelector:
matchLabels:
app.kubernetes.io/component: web
policyTypes: [Ingress]
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-system
podSelector:
matchLabels:
app.kubernetes.io/name: ingress-controller
ports:
- protocol: TCP
port: 8080
Replace the namespace, labels and port with those of your controller, whether that is an Ingress controller or a Gateway API implementation.
Selecting a namespace by name. NetworkPolicy has no "namespace name" field. The control plane sets an immutable label, kubernetes.io/metadata.name, on every namespace, with the namespace's name as its value. Use it. A label you add yourself can be added to another namespace by anyone allowed to label namespaces.
The indentation trap. In the example, namespaceSelector and podSelector are in one list element. That means "pods with this label in that namespace". Put a dash before podSelector and it becomes two elements: "any pod in that namespace, or pods with this label in my namespace". Both are valid YAML. The docs suggest kubectl describe networkpolicy to see how Kubernetes read it.
Host-network controllers. If the controller runs with hostNetwork: true, selectors will probably not match it. See the limits below.
5. Monitoring
Prometheus scrapes pods directly, so each scraped pod needs an ingress rule:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-metrics-scrape
namespace: shop
spec:
podSelector: {}
policyTypes: [Ingress]
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: monitoring
ports:
- protocol: TCP
port: 9090
Set the port to your metrics port. If the monitoring namespace has its own egress deny, it needs the matching egress rule.
What the baseline leaves out
Anything else a workload needs is an explicit egress rule: a database in another namespace, an external API, the Kubernetes API server.
External destinations use ipBlock. Egress to the API server is awkward. Pods reach it through a Service address that is rewritten to the control plane's address, and the docs say such connections "may or may not be subject to ipBlock-based policies", depending on the plugin. Expect to test this per cluster, and expect controllers and operators to be the workloads that need it.
Pods the API server calls. Admission and conversion webhooks and aggregated APIs take connections from the API server. Often that is a control-plane or node address needing an ipBlock. On GKE 1.36.4 it was the konnectivity-agent pods in kube-system, and only a selector for them worked. Allow the right source before the default deny lands. A blocked webhook with failurePolicy: Fail rejects every API request it matches.
A rollout order that doesn't cause an outage
The trap is in the first rule of the model: any policy that selects a pod isolates it. You cannot apply the allow rules first and the deny later, because the first allow policy already denies everything else.
The additive rule gives you a way round. A policy that allows everything, combined with any other policy, still allows everything.
Step 1. Record what talks to what. Flow logs from your CNI plugin, service mesh telemetry, or the owners of the workloads.
Step 2. Apply an allow-all policy to the namespace. It changes nothing by itself, but suspends any policies already there.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: temporary-allow-all
namespace: shop
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
ingress:
- {}
egress:
- {}
Step 3. Apply the baseline and your specific allows. Still no effect, because the union includes "everything".
Step 4. Delete temporary-allow-all. This is the moment of enforcement. Do it for one namespace at a time, when the owning team is watching.
Step 5. If something breaks, re-apply temporary-allow-all. Access returns as soon as the plugin processes it. Then add the missing rule and try again.
Step 6. Restart the workloads. The docs state that the effect of a policy change on existing connections is "implementation defined". A long-lived database connection may survive the cut-over and hide a missing rule until the next restart. A rolling restart shows you now.
Order the namespaces by risk: a non-production application namespace first, shared platform namespaces later. Treat kube-system separately. Its components include host-network pods and things every node depends on. Leaving it without a default deny is defensible if it is a decision and not an oversight.
Two more behaviours from the docs:
- Policies are not instant. There is "no way to tell from the Kubernetes API" when a plugin has finished handling a policy.
- New pods may briefly have no connectivity. Isolation is applied before a pod starts, and allow rules may follow slightly later. Applications that fail permanently when their first connection attempt fails will have trouble. The docs suggest an init container that waits for the destination.
What NetworkPolicy cannot do
From the docs' list, the entries that matter most:
| Limit | Consequence |
|---|---|
| No deny rules | You cannot write "everything except X". You can only avoid allowing X. |
| No cluster-wide default | Every namespace needs its own policies. A new namespace starts wide open. |
| Layer 4 only | TCP, UDP and SCTP ports. No HTTP paths, methods or hostnames, and nothing TLS-related. |
| No logging | The API has no way to record blocked or allowed connections. Your plugin may. |
| No targeting Services by name | You select pods and namespaces by label. |
| No node identity | Nodes can be addressed only by CIDR. |
| Cannot block the pod's own node | Traffic from the resident node and localhost is always allowed. |
| Other protocols undefined | A deny-all is "only guaranteed to deny TCP, UDP and SCTP". ICMP behaviour depends on the plugin. |
Host-network pods. The docs call the behaviour "undefined" and describe the most common implementation: the plugin ignores hostNetwork pods when matching selectors, and treats their traffic as traffic from the node's address. A policy that selects a host-network pod does not protect it. And to allow traffic from a host-network ingress controller on another node, you need an ipBlock covering your node addresses, which admits everything else on those nodes too.
Source addresses at the edge. For traffic entering through a load balancer, the address a policy sees may be the client's, the load balancer's or a node's. The docs say this is not defined and varies by plugin, cloud provider and Service implementation. Don't build an ipBlock allow-list of client addresses without testing what arrives.
Identity. A policy trusts pod labels and namespaces. Anyone who can create a pod with the right labels in an allowed namespace gets the access. For proof of who is calling, you need authentication on the connection, which is where Pod Certificates come in.
Cluster-wide policy: where AdminNetworkPolicy went
The two biggest gaps, no deny rules and no cluster-wide default, are what SIG Network's Network Policy API project addresses.
| Date | Release | What happened |
|---|---|---|
| Up to July 2025 | v0.1.x | AdminNetworkPolicy and BaselineAdminNetworkPolicy, API version v1alpha1 |
| 21 April 2026 | v0.2.0 | Both merged into one resource, ClusterNetworkPolicy, version v1alpha2, with a tier field. The Allow action was renamed Accept. |
| 6 November 2026 | v0.3.0 | ClusterNetworkPolicy graduated to v1beta1, now the storage version. v1alpha2 is still served and the schemas are identical. |
The project site now lists AdminNetworkPolicy and BaselineAdminNetworkPolicy as previous APIs that are no longer actively developed. If a guide tells you to write an AdminNetworkPolicy, it predates April 2026.
What ClusterNetworkPolicy adds, per the project's API overview:
- Three tiers, evaluated in order: Admin, then NetworkPolicy, then Baseline. An Admin-tier rule wins over any namespace NetworkPolicy. A Baseline-tier rule applies only where no NetworkPolicy has decided.
- Explicit actions:
Accept,DenyandPass.Passhands the decision to the next tier, which lets an administrator delegate a class of traffic to namespace owners. - Priorities within a tier, where a lower number takes precedence.
The Baseline tier is the cluster-wide default deny that NetworkPolicy lacks, covering new namespaces from the moment they exist. The Admin tier gives you rules a namespace owner cannot override.
Three cautions:
- It is not part of Kubernetes. It is a CRD in the
policy.networking.k8s.iogroup that you or your platform install, and nothing happens unless your network plugin implements it. Upgrading to v1.37 does not give it to you. - Beta, and released on 6 November 2026. The release notes defer deprecating
v1alpha2"to a future release oncev1beta1has soaked". - Plugin support varies. The project's implementations page (self-reported, dated 21 April 2026, so before
v1beta1) lists kube-network-policies, Calico v3.32 and, experimentally, Kube-OVN. Check your plugin's documentation.
Until your plugin supports it, create the baseline policies from the same template or pipeline that creates the namespace, and check for gaps.
comm -23 \
<(kubectl get ns -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | sort) \
<(kubectl get networkpolicy -A -o jsonpath='{range .items[*]}{.metadata.namespace}{"\n"}{end}' | sort -u)
That lists namespaces with no NetworkPolicy at all.
Checklist
- Enforcement: prove in a scratch namespace that your CNI plugin enforces policies.
- Baseline per namespace: default deny for ingress and egress, DNS egress on UDP and TCP, and an explicit decision on same-namespace traffic.
- Named exceptions: ingress controller and monitoring, selected with
kubernetes.io/metadata.name. - Rollout: allow-all first, then the real policies, then remove the allow-all, one namespace at a time, followed by a restart.
- Limits: list your host-network pods and decide how they are protected, because policies don't do it.
- New namespaces: create policies with the namespace, and run the gap check regularly.
- Sensitive components: give them their own tighter policies, as in the Argo CD repo-server example.