Sub topic 4
Who Enforces Policies: The Network Plugin
This chapter assumes you know pods, Services, namespaces, labels, and how to apply YAML with kubectl. It explains which component actually enforces a NetworkPolicy. A policy that nothing enforces has no effect.
The API stores policies, it does not enforce them
A NetworkPolicy is an object in the Kubernetes API. The API server validates it and saves it in etcd. No built-in Kubernetes component reads it and changes traffic.
Enforcement belongs to the network plugin. This is the plugin that implements the Container Network Interface (CNI), the standard that gives pods their network connections. The plugin watches NetworkPolicy objects and turns them into packet filtering rules on each node. Depending on the plugin, those rules use iptables, nftables, or eBPF programs.
How enforcement flows
Each node runs an agent from the plugin. The agent watches for policy, pod, and namespace changes. When they change, it recomputes the rules for the pods on its node. This is why policy changes apply within seconds and need no pod restarts.
Plugin support varies
Support depends on the plugin you installed, not on the Kubernetes version.
| Plugin | Enforces NetworkPolicy |
|---|---|
| Calico | Yes |
| Cilium | Yes |
| Antrea | Yes |
| Weave Net | Yes |
| Flannel (alone) | No |
Flannel only provides pod networking. A common setup pairs it with Calico for policy only. Managed services differ: some enable enforcement with a setting, and others ship a plugin that includes it. Check your provider's documentation.
Check what your cluster runs
List the plugin's pods in kube-system and look at their names:
kubectl get pods -n kube-system -o wideNames such as calico-node, cilium, or antrea-agent show the plugin. You can also look at the CNI configuration on a node, usually under /etc/cni/net.d/.
Common errors
- Assuming a policy works because it applied. Always test it. The chapter on testing shows how, using temporary client pods.
- Switching plugins without checking policy support. Existing policies may stop being enforced and the cluster silently becomes open again.
- Expecting identical behavior everywhere. The core API defines the rules. Plugins differ in details such as logging, performance, and extra features. Later chapters cover those extensions.
Exercise
You apply a default-deny NetworkPolicy in a test cluster. kubectl get networkpolicy shows it, but a test pod can still reach every other pod. What is the most likely cause, and how do you check it?
Show answer
The cluster's network plugin probably does not enforce NetworkPolicy, as with Flannel alone. The API accepts the object, but nothing turns it into packet filter rules. Check which plugin runs, for example with kubectl get pods -n kube-system, and look for a plugin that supports policy such as Calico or Cilium.