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].
- 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 - Modify Network CIDR: You must edit the
kube-flannel.ymlfile. Locate theNetworkconfiguration within the file and ensure it matches the CIDR block used inkubeadm init^[400-devops-06-kubernetes-k8s-learning-00install-01-kubernetes.md].- Example Change: If
--pod-network-cidr=192.168.0.0/16was 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].
- Example Change: If
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].
Related Concepts¶
- Kubernetes
- [[CNI]]
- [[kubeadm]]
- [[Pod network]]