This document provides detailed steps to set up a multi-node Kubernetes cluster using kubeadm and Flannel as the pod network. The configuration includes a single master node and multiple worker nodes.
In this demo, I will demonstrate how to create a connection between the master and one worker node using kubeadm and provide the installation steps.
Prerequisites
Operating System: Ubuntu 20.04/22.04 or compatible versions
Minimum System Requirements:
Master Node: 2 CPUs, 2 GB RAM
Worker Nodes: 1 CPU, 1 GB RAM per node
Steps to Set Up Kubernetes Multi-Node Cluster:
1.Update and Install Required Tools
sudo apt-get update
sudo apt install apt-transport-https curl -y
2.Add Docker’s Official GPG Key and Repository
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
3. Install containerd
sudo apt-get install containerd.io -y
4.Configure Containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i -e 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
sudo systemctl restart containerd
5. Install Kubernetes Components
Add Kubernetes Signing Key and Repository
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg]
https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
6.Install Kubernetes Tools
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
7.Enable kubelet Service
sudo systemctl enable --now kubelet
8.Disable Swap
sudo swapoff -a
sudo sed -i '/swap/d' /etc/fstab
9.Load Kernel Modules
sudo modprobe br_netfilter
sudo sysctl -w net.ipv4.ip_forward=1
Commands for Master Node Only
10. Initialize the Kubernetes Cluster
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
11. Set Up kubeconfig
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
12. Install Pod Network (Flannel)
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
13. Verify Cluster Components
kubectl get pods --all-namespaces
14 . Add Worker Nodes to the Cluster:
sudo kubeadm join <master-ip>:6443 --token <TOKEN> --discovery-token-ca-cert-hash
sha256:<HASH>
15.Confirm the worker node joined the cluster
kubectl get nodes
Conclusion:
Setting up a multi-node Kubernetes cluster with kubeadm is straightforward and efficient. With Flannel managing the pod network, the master and worker nodes can communicate seamlessly, making the cluster ready for your applications.
Happy Learning
Prithiviraj Rengarajan
DevOps Engineer