Skip to content

Flannel CNI installation for Kubernetes

Flannel is a network fabric designed for Kubernetes that enables the communication between Pods across different nodes^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md]. It functions as a CNI (Container Network Interface) plugin and is typically installed immediately after the cluster initialization process^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].

Prerequisites

Before installing Flannel, the Kubernetes cluster must be initialized, and the master node (control plane) must be configured^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md]. During the initialization step (e.g., using kubeadm init), a specific CIDR block is defined for the Pod network using the --pod-network-cidr flag^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].

Configuration

The Flannel configuration requires that its network definition matches the pod-network-cidr specified during cluster initialization^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].

  1. Download the Manifest: The official Flannel deployment file is typically retrieved from the CoreOS Flannel repository^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].
    wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    
  2. Modify Network CIDR: You must edit the kube-flannel.yml file. Locate the Network configuration within the file and ensure it matches the CIDR block used in kubeadm init^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].
    • Example Change: If --pod-network-cidr=192.168.0.0/16 was used, update "Network": "10.244.0.0/16" to "Network": "192.168.0.0/16"^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].

Installation

Apply the modified configuration to the cluster using kubectl^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].

[kubectl](<./kubectl.md>) apply -f kube-flannel.yml

Verification

Once installed, Flannel creates several Kubernetes resources, including a DaemonSet named kube-flannel-ds to run the Flannel agent on every node^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md]. You can verify that the installation was successful by checking the status of the nodes^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].

Before Flannel is installed, nodes typically remain in a NotReady state because the container network interface is missing^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md]. After applying the Flannel configuration, the nodes should transition to the Ready status^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].

Sources