> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Flannel vs Canal The Problem

> Comparison of Flannel versus Canal via reproducible tests showing that Flannel provides simple overlay networking while Canal adds Calico based NetworkPolicy enforcement

Which is better for your cluster: Flannel or Canal?

Bob sets out to answer that question by running the same experiment on two clusters:

* Cluster one runs Flannel.
* Cluster two runs Canal (Flannel + Calico).

Both plugins aim to give Pods a network and connect Pods across nodes, but they differ in capability—most importantly in how (or whether) they enforce Kubernetes NetworkPolicy.

What follows is a concise explanation of the differences, then the exact steps Bob uses to test them so you can reproduce the experiment.

## What Flannel does

[Flannel](https://github.com/flannel-io/flannel) (originally from CoreOS) is designed for simplicity. It creates an overlay network so Pods behave as if they are on the same flat network even when they live on different nodes. Because Flannel runs on top of the host network, it's easy to set up and doesn't require special hardware.

However, Flannel by itself does not implement NetworkPolicy enforcement. That means NetworkPolicy objects you create in the Kubernetes API server are only effective if a CNI datapath that supports policy enforcement is present (for example, Calico or Cilium).

NetworkPolicy objects are API resources only. They only take effect if the underlying CNI plugin (or an additional datapath) enforces them. If the CNI lacks policy enforcement, policies are accepted by Kubernetes but do nothing.

## What Canal is

[Canal](https://github.com/projectcalico/canal) packages two pieces:

* Flannel — provides the simple overlay network.
* Calico — provides policy enforcement and other datapath features.

Canal combines Flannel's overlay with Calico's NetworkPolicy enforcement so you get easy networking plus real policy controls.

## Bob's experiment (reproducible steps)

Bob uses identical workloads and tests on both clusters. The only difference is the installed CNI:

1. Deploy two nginx Pods in the `default` namespace on each cluster.
   * Cluster one: Pods named `KodeKloud` and `Community`.
   * Cluster two: Pods named `Alpha` and `Beta`.
2. Test connectivity by running curl from one Pod to the other Pod's IP.
3. Apply a `deny-all` NetworkPolicy to the `default` namespace on both clusters.
4. Re-run the same curl tests.

Example of running curl from inside a pod:

```bash theme={null}
# From the 'kodekloud' pod, request the web page served by Pod IP 10.244.2.3
kubectl exec kodekloud -- curl http://10.244.2.3
```

If the welcome page is returned, the two pods can reach each other.

### The deny-all NetworkPolicy

Bob applies the same policy YAML to both clusters:

```yaml theme={null}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-all
  namespace: default
spec:
  podSelector: {}
  policyTypes:
    - Ingress
    - Egress
  ingress: []
  egress: []
```

* `podSelector: {}` selects all pods in the namespace.
* `policyTypes` includes both `Ingress` and `Egress` so the policy governs incoming and outgoing traffic.
* Empty `ingress: []` and `egress: []` effectively allow no traffic to/from the selected pods.

Apply it with:

```bash theme={null}
kubectl apply -f deny-all.yaml
```

Then re-run the curl tests from the same pods.

## Key questions Bob wants to answer

* What is the role of the CNI?
  * The CNI standardizes how container networking is configured. Individual CNI plugins implement datapath behavior and may optionally enforce NetworkPolicy.
* Which plugin is running on cluster one?
  * Flannel.
* Which plugin actually enforces NetworkPolicy?
  * Calico (or another policy-capable CNI such as Cilium) enforces NetworkPolicy. Flannel on its own does not.

## Quick comparison

| Feature | Flannel | Canal (Flannel + Calico) |
| -: | :- | :- |
| Overlay networking | Yes (`flannel`) | Yes (`flannel`) |
| NetworkPolicy enforcement | No (by itself) | Yes (via `calico`) |
| Complexity | Low | Medium (adds Calico components) |
| Typical use-case | Simple clusters where policy enforcement is not required | Clusters needing simple overlay + policy enforcement |

## Expected vs. actual behavior

* Before the `deny-all` policy: curl tests should succeed on both clusters (Kubernetes allows pod-to-pod traffic by default).
* After applying `deny-all`:
  * On the Canal cluster (Flannel + Calico): NetworkPolicy enforcement should block the curl requests.
  * On the Flannel-only cluster: Because Flannel does not enforce NetworkPolicy, the curl requests may still succeed even though the `deny-all` object exists in the API.

Applying a NetworkPolicy object does not guarantee traffic is blocked. If your cluster’s CNI plugin does not implement policy enforcement, the NetworkPolicy resource will be ignored at datapath time. Always verify behavior after applying policies.

Everything else in the experiment (Pods, test method, policy file) is identical between clusters; the only variable is the CNI implementation.

So once `deny-all` is applied, will curl still return the welcome page? The answer depends on whether the CNI enforces NetworkPolicy—on Flannel-only it likely will, on Canal it should not.

## Links and references

* [Flannel GitHub](https://github.com/flannel-io/flannel)
* [Canal GitHub](https://github.com/projectcalico/canal)
* [Calico](https://projectcalico.org/)
* [Kubernetes NetworkPolicy docs](https://kubernetes.io/docs/concepts/services-networking/network-policies/)
* [CNI project](https://www.cni.dev/)
* [Cilium](https://cilium.io/)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/learn-by-doing-kubernetes-network-policies/module/e7fde9a6-ce21-4c90-a3c6-a7530076e87e/lesson/acb87542-6763-441a-b0c3-50d12eee35b7)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.