> ## 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.

# Installing a CNI Hands On

> Install Flannel and Canal CNIs on Kubernetes clusters by applying manifests, running DaemonSets, switching contexts, verifying pods and node readiness, and noting NetworkPolicy enforcement differences

How does a CNI (Container Network Interface) plugin get installed onto a Kubernetes cluster? With a single command.

Most CNIs (including Flannel and Canal) are installed by applying a manifest: a YAML file that declares one or more Kubernetes objects. You give that file to `kubectl apply`, and Kubernetes creates everything declared inside. For CNIs the most important object in these manifests is a DaemonSet.

A DaemonSet ensures one copy of a pod runs on each node — exactly what a networking plugin needs so every node receives a pod network.

```yaml theme={null}
apiVersion: apps/v1
kind: DaemonSet

metadata:
  labels:
    app: flannel
    k8s-app: flannel
    tier: node
  name: kube-flannel-ds
  namespace: kube-flannel
spec:
  selector:
    matchLabels:
      app: flannel
      k8s-app: flannel
  template:
    # Pod template goes here...
```

Once a DaemonSet is created, every node runs the plugin pod and therefore gets configured with the pod network the CNI provides.

In this guide we use the official manifests for Flannel and Canal. Always get the manifest URL from the plugin’s official install page:

* Flannel manifest: [https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml](https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml)
* Canal manifest: [https://docs.projectcalico.org/manifests/canal.yaml](https://docs.projectcalico.org/manifests/canal.yaml)

Before applying manifests, make sure your kubectl commands target the correct cluster context.

You can either:

* add `--context` to each `kubectl` command, e.g. `kubectl --context=cluster1 get nodes`, or
* switch contexts once with `kubectl config use-context cluster1` so subsequent commands go to that cluster.

## Step 1 — Install Flannel on cluster1

Switch to `cluster1` and apply the Flannel manifest (replace the example URL with the official Flannel manifest URL if it changes):

```bash theme={null}
$ kubectl config use-context cluster1
Switched to context "cluster1".
$ kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
```

Kubernetes creates the Flannel objects and the DaemonSet. One Flannel pod will be scheduled on each node. For example, if `cluster1` has three nodes, three Flannel pods appear.

Within a few moments the node statuses should change. `kubectl get nodes` will show nodes as `Ready`. Why does this happen? The kubelet (the node agent) needs the pod network provided by a CNI plugin to finish configuring pod networking. Once the CNI is available, the kubelet completes setup and the node transitions from `NotReady` to `Ready`.

Deployments or pods that were waiting for a network can now be scheduled and will move to `Running`:

```bash theme={null}
$ kubectl get pods
NAME                             STATUS
deploy-a-5d8f7c6b9-4xkzp        Running
deploy-a-5d8f7c6b9-r7tq2        Running
```

## Step 2 — Install Canal on cluster2

Switch to `cluster2` and apply the Canal manifest (again, use the official manifest URL if changed):

```bash theme={null}
$ kubectl config use-context cluster2
Switched to context "cluster2".
$ kubectl apply -f https://docs.projectcalico.org/manifests/canal.yaml
```

Canal also runs as a DaemonSet, so one pod starts on each node. If `cluster2` has two nodes, you’ll see two Canal pods. The nodes will move from `NotReady` to `Ready` as the CNI becomes available, and any previously unschedulable pods will reach `Running`.

## Verification checklist

Bob verifies the clusters:

* On `cluster1` list pods across all namespaces and confirm three Flannel pods are `Running`.\
  Example:
  * `kubectl --context=cluster1 get pods -A`
* On `cluster2` list pods and confirm two Canal pods are `Running`.\
  Example:
  * `kubectl --context=cluster2 get pods -A`
* All five nodes (three in cluster1, two in cluster2) now report `Ready`.
* Deployment A pods and Pod B are `Running`.

Now both clusters have working pod networking; externally they look the same: nodes are `Ready` and pods are `Running`.

## CNI differences and NetworkPolicy

Note that different CNIs have different feature sets. In particular, support for Kubernetes NetworkPolicy depends on the plugin:

| CNI | Runs as DaemonSet | NetworkPolicy enforcement |
| - | - | - |
| Flannel | Yes | Basic Flannel modes may not enforce `NetworkPolicy` (store-only in some configurations) |
| Canal (Calico + Flannel) | Yes | Typically enforces `NetworkPolicy` (Calico provides enforcement) |

Note: Applying the same NetworkPolicy to both clusters does not guarantee identical behavior. One cluster may actively enforce policies, while another may accept and store them without enforcing. Always confirm NetworkPolicy support in the CNI documentation before relying on policies for network isolation.

## Summary

* A CNI is typically installed by applying a manifest that includes a DaemonSet, which ensures one plugin pod per node.
* Use `kubectl config use-context <context>` or `--context` to point kubectl at the correct cluster before applying manifests.
* After installing a CNI, nodes should move to `Ready` and pods will be scheduled normally.
* Choose a CNI that matches your feature needs (for example, NetworkPolicy enforcement).

## Links and references

* Flannel install manifest: [https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml](https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml)
* Canal (Project Calico) manifest: [https://docs.projectcalico.org/manifests/canal.yaml](https://docs.projectcalico.org/manifests/canal.yaml)
* Kubernetes Documentation: [https://kubernetes.io/docs/](https://kubernetes.io/docs/)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/learn-by-doing-kubernetes-network-policies/module/7c56719e-7a67-419e-a2fb-be8709b49200/lesson/23610ce5-16b9-4b94-a825-4db628b8bceb)

> [card] [Practice Lab](https://learn.kodekloud.com/user/courses/learn-by-doing-kubernetes-network-policies/module/7c56719e-7a67-419e-a2fb-be8709b49200/lesson/c940433a-7e3f-47d8-aff5-3cfed815c597)


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