DEV Community

Prithiviraj R
Prithiviraj R

Posted on

Setting Up a Multi-Node Kubernetes Cluster with kubeadm

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  
Enter fullscreen mode Exit fullscreen mode

3. Install containerd

sudo apt-get install containerd.io -y 
Enter fullscreen mode Exit fullscreen mode

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  
Enter fullscreen mode Exit fullscreen mode

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  
Enter fullscreen mode Exit fullscreen mode

6.Install Kubernetes Tools

sudo apt-get install -y kubelet kubeadm kubectl  
sudo apt-mark hold kubelet kubeadm kubectl 
Enter fullscreen mode Exit fullscreen mode

7.Enable kubelet Service

sudo systemctl enable --now kubelet  
Enter fullscreen mode Exit fullscreen mode

8.Disable Swap

sudo swapoff -a  
sudo sed -i '/swap/d' /etc/fstab  
Enter fullscreen mode Exit fullscreen mode

9.Load Kernel Modules

sudo modprobe br_netfilter  
sudo sysctl -w net.ipv4.ip_forward=1
Enter fullscreen mode Exit fullscreen mode

Image description

Commands for Master Node Only

10. Initialize the Kubernetes Cluster

sudo kubeadm init --pod-network-cidr=10.244.0.0/16 
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

Image description

12. Install Pod Network (Flannel)

kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml 
Enter fullscreen mode Exit fullscreen mode

Image description

13. Verify Cluster Components

kubectl get pods --all-namespaces
Enter fullscreen mode Exit fullscreen mode

Image description

14 . Add Worker Nodes to the Cluster:

sudo kubeadm join <master-ip>:6443 --token <TOKEN> --discovery-token-ca-cert-hash
sha256:<HASH>
Enter fullscreen mode Exit fullscreen mode

Image description

15.Confirm the worker node joined the cluster

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

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

Top comments (0)