Skip to main content
In this lesson we run a short experiment to confirm how different CNI plugins handle Kubernetes NetworkPolicies. We’ll compare a Flannel-only cluster with a Canal cluster (Flannel + Calico) and apply the same “deny-all” NetworkPolicy to observe enforcement differences. Bob starts with a warm-up question: What is a CNI for? Answer: to establish and manage container networking — creating pod IPs, routing between pods, and (optionally) enforcing NetworkPolicy.
A slide titled "What Is a CNI For?" showing two panels labeled cluster1 (with Flannel) and cluster2 (with a Canal box containing Flannel and Calico icons). A small avatar labeled "Bob" is on the left and a KodeKloud logo sits in the bottom-left.
Overview
  • Goal: verify whether a “deny-all” NetworkPolicy actually blocks traffic on two clusters that use different CNIs.
  • Cluster layout:
    • cluster1: Flannel (pod networking only; no NetworkPolicy enforcement)
    • cluster2: Canal (Flannel for networking + Calico for policy enforcement)

1) Inspect cluster1 (Flannel)

Switch kubeconfig context to cluster1 and list pods across all namespaces to find the Flannel DaemonSet:
DS = DaemonSet — one Flannel pod per node. To confirm the plugin type you can inspect the CNI configuration on the control plane:
This shows the cluster is configured with Flannel.

Create two test pods (cluster1)

Create two NGINX pods in the default namespace and check their IPs:
From kodekloud curl the community pod IP to verify connectivity (should return the NGINX welcome page):

Apply a “deny-all” NetworkPolicy (cluster1)

Create the following policy which intends to block all ingress and egress for pods in the default namespace:
Apply it:
Re-run the curl from kodekloud to community:
Observation and explanation:
  • Even after the policy object exists, traffic is still allowed. Flannel sets up the pod network but does not implement NetworkPolicy enforcement. The NetworkPolicy resource is stored in the API server, but Flannel does not enforce it — so connectivity remains unchanged.

2) Inspect cluster2 (Canal = Flannel + Calico)

Switch context to cluster2 and create two more NGINX pods, alpha and beta:
Verify connectivity before applying policy:
Apply the same deny-all policy in the default namespace on cluster2:
After Calico reads and enforces the policy, requests are blocked:
Observation and explanation:
  • Canal uses Flannel for pod networking but runs Calico on each node for policy enforcement. Calico implements and enforces NetworkPolicy; therefore the same deny-all policy blocks traffic in cluster2.

Why the different behavior?

Summary table: Key point: A NetworkPolicy resource only has effect when the CNI plugin actually implements enforcement. Flannel provides networking but does not enforce policies; Calico provides enforcement.
A NetworkPolicy object only takes effect when the cluster’s CNI plugin implements enforcement. Some CNI plugins (like Calico) enforce NetworkPolicy; others (like Flannel alone) do not.
Additional notes and best practices
  • The empty podSelector: {} in the policy selects all pods in the namespace — that is intentional for a true “deny-all” policy.
  • When testing NetworkPolicy behavior, always confirm:
    • Which CNI components are installed (DaemonSets, Config files).
    • That Calico or another policy-capable CNI is present when expecting enforcement.
  • For reproducible verification use pod IPs shown by kubectl get pods -o wide and kubectl exec to run client requests.
Conclusion
  • A NetworkPolicy will only restrict traffic if the underlying CNI implements enforcement. For hands-on policy work and verifiable rule enforcement, use clusters that include a policy-capable CNI (e.g., Calico). From here on, Bob will continue experiments only on clusters where NetworkPolicies are actually enforced.

Watch Video

Practice Lab