Skip to main content

Command Palette

Search for a command to run...

Setting Up a Multi-Node Kubernetes Cluster Using Kubeadm on Ubuntu 24.04 LTS

Updated
5 min read
Setting Up a Multi-Node Kubernetes Cluster Using Kubeadm on Ubuntu 24.04 LTS

Kubernetes is a powerful platform for managing containerized workloads, and Kubeadm is a tool for setting up a Kubernetes cluster easily. In this guide, we'll walk you through the process of setting up a multi-node Kubernetes cluster on Ubuntu 24.04 LTS using Kubeadm. The setup is straightforward and includes all the necessary steps for beginners.

Prerequisites

Before you begin, make sure you meet the following requirements:

  • At least two Ubuntu 24.04 LTS servers with 2GB of RAM and 2 CPU cores.

  • Network connectivity between the servers.

  • Root (sudo) access to each server.

Step 1: Update the System and Install Dependencies

Start by updating the system and installing the necessary dependencies on all nodes (both master and worker nodes).

sudo apt update && sudo apt upgrade -y
sudo apt install apt-transport-https curl -y

Step 2: Install and Configure Containerd

Kubernetes uses containerd as the container runtime. Let's install and configure it:

sudo apt install containerd -y

Now configure containerd to use systemd as the cgroup driver:

sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
sudo systemctl restart containerd

Step 3: Install Kubernetes Components

Next, we'll install the Kubernetes components: kubelet, kubeadm, and kubectl. These are the essential tools for setting up and managing the Kubernetes cluster.

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.33/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.33/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
sudo systemctl enable --now kubelet

Step 4: Disable Swap

Kubernetes requires that swap be disabled for proper node functioning. Disable it by running:

sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Step 5: Load Necessary Kernel Modules

Kubernetes requires certain kernel modules for networking. Load these modules by running the following commands:

sudo modprobe overlay
sudo modprobe br_netfilter

Step 6: Set Required Sysctl Parameters

To ensure proper network communication, set the following sysctl parameters:

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF

Apply these sysctl settings:

sudo sysctl --system

Step 7: Initialize the Kubernetes Cluster (on the Master Node)

Now that the nodes are configured, it's time to initialize the Kubernetes cluster. Run the following command only on the master node:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

This command will provide a kubeadm join command that you'll use later to join worker nodes to the cluster.

Step 8: Set Up kubeconfig for the User

To interact with the Kubernetes cluster using kubectl, set up the kubeconfig file for your user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Step 9: Install a Network Plugin (Flannel)

Kubernetes requires a network plugin to enable communication between pods across different nodes. We will use Flannel for this purpose. Run the following command on the master node:

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

Step 10: Verify the Installation

To verify that your cluster is up and running, check the status of the nodes and pods:

kubectl get nodes
kubectl get pods --all-namespaces

Step 11: Join Worker Nodes to the Cluster

On the worker nodes, run the kubeadm join command provided by the kubeadm init output on the master node. It will look something like this:

sudo kubeadm join 172.31.19.36:6443 --token 922x9d.v0jn4c8he0s286js --discovery-token-ca-cert-hash sha256:abcd1234...

After running the kubeadm join command on the worker nodes, they will join the cluster.

Step 12: Verify the Cluster

On the master node, run the following command to ensure that all nodes have joined the cluster successfully:

kubectl get nodes

You should see the master and worker nodes listed as Ready.


Conclusion

Congratulations! You have successfully set up a multi-node Kubernetes cluster using Kubeadm on Ubuntu 24.04 LTS. You can now start deploying your applications on this cluster. If you face any issues during the setup, check the logs or consult the Kubernetes documentation for more troubleshooting steps.


🔍 Understanding Kubernetes System Pods After Cluster Initialization

After initializing your Kubernetes cluster with kubeadm, you can run the command:

kubectl get pods -n kube-system

This will list the core system components running in the kube-system namespace. Here's what each of them does:

Pod NamePurpose
calico-kube-controllersControls the state of Calico network policies and routes. It ensures proper communication between nodes.
calico-nodeRuns on every node and is responsible for setting up networking, routing, and enforcing network policies.
corednsDNS server for service discovery in the cluster. It allows pods to resolve service names like my-service.default.svc.cluster.local.
etcdA distributed key-value store used as the backing store for all cluster data. Critical for cluster state.
kube-apiserverExposes the Kubernetes API. It's the front-end and primary control plane component.
kube-controller-managerManages various controllers (e.g., replication, endpoint, namespace). It ensures the desired state of resources.
kube-proxyMaintains network rules on nodes to allow communication to services. Handles routing traffic to appropriate pods.
kube-schedulerAssigns newly created pods to nodes based on resource availability and scheduling rules.
10 views

Kubernetes from Scratch

Part 1 of 3

In this series, I’ll guide you from setting up your local environment to building, deploying, and managing Kubernetes clusters, covering essential concepts, tools, and hands-on examples — perfect for beginners and improvers.

Up next

How to Install KVM on Ubuntu: A Step-by-Step Beginner’s Guide

If you're diving into the world of virtualization on Linux, KVM (Kernel-based Virtual Machine) is one of the best technologies you can use. It’s powerful, free, built right into the Linux kernel, and acts like a Type 1 hypervisor — just like VMware E...

More from this blog

Iresh's Blog

20 posts