Skip to main content

Command Palette

Search for a command to run...

Kubernetes Installation using Kubeadm on ubuntu 24.04 (LTS)

Updated
6 min read
Kubernetes Installation using Kubeadm on ubuntu 24.04 (LTS)
O

Hi there! I'm Ojas Jawale, a passionate Cloud, DevOps and Cyber Security enthusiast. I love to dive into the latest new technologies and sharing my journey through blog. I'm always eager to learn and grow in this ever-evolving field of DevOps and Cyber Security. You'll find me writing about CI/CD pipelines, automation, containerization with Docker, and other exciting tech topics related to software quality and deployment. My goal is to demystify complex DevOps and Cyber Security concepts, provide practical tips on automation and testing, and inspire others in the developer and operations community. Let's connect, learn, and build amazing, high-quality software together!

For Kubernetes architecture refer -> k8s Architecture

In this tutorial, learn how to install and configure Kubernetes (K8s) on Ubuntu 24.04 with this step-by-step guide. Ensure seamless Kubernetes setup with Docker, kubeadm, and kubectl.

Kubernetes (K8s) has become the leading platform for container orchestration, enabling developers to deploy, manage, and scale applications with ease. As more organizations adopt microservices architectures, mastering Kubernetes is essential for efficient DevOps workflows.

Whether you're a beginner looking to get started with Kubernetes or an experienced developer seeking a reliable reference, this tutorial covers everything from installing Docker, the necessary container runtime, to configuring kubeadm, kubelet, and kubectl.


What is Kubeadm?

Kubeadm is the “hard way” to begin with Kubernetes. With this solution, you will be able to bootstrap a minimum viable Kubernetes cluster that conforms to best practices. The cluster minimal size is composed of two nodes:

  • Master node

  • Worker node

and you can add as many workers as you want.

But this solution is quite heavy to run on a laptop. Each node should be deployed in a virtual machine and the minimal requirements are:

  • Memory: 2 GB

  • CPU: 2 (only for the master)

If you want to deploy a cluster with several nodes you must have a quite powerful computer. But you will be able to discover the full potential of Kubernetes. Here is a tutorial to help you to deploy your first Kubernetes cluster using Kubeadm.

  • Kubeadm allows us to customize and configure our clusters according to our needs and preferences. We can configure things like the network plugin, authentication and authorization mechanisms, and storage solutions.

  • Kubeadm is the recommended way to create a Kubernetes cluster, so using it for learning and testing ensures that we are following the best practices recommended by the Kubernetes community.


  1. Prerequisites

  • Ubuntu 24.04 LTS installed on all machines (1 master node and at least 1 worker node).

  • Minimum instance required to create cluster = 2 (Master 1 and Worker 1)

  • Root or sudo access to the machines.

  • At least 2GB of RAM per machine (4GB recommended for the master node).

  • Make sure your all instance are in same Security group.

  • Expose port 6443 in the Security group, so that worker nodes can join the cluster.


  1. Step 1 : Create an instance for master and worker on AWS EC2

  • Go to AWS console -> EC2 -> Launch Instance

  • Name : master-node

  • AMI : Ubuntu 24.04

  • Instance type : t2.medium

  • Create Key pair

  • Security group : Create new security group

  • Click on "Launch Instance".

  • Note that security group of master-node : launch-wizard-3

  • Create follow above same steps to create instance for worker-node.

  • Note : Create worker-node in same security group master-node has.

  • same key of master-node so that both instance can communicate with each other.

Important,

Select security group : launch-wizard-3

  • Click on "Launch Instance".

  • Connect both instances using SSH key created and then follow next steps.


  1. Step 2 : Update and Upgrade the System

  • Start by updating the package list and upgrading the installed packages to the latest versions.
sudo apt update && sudo apt upgrade -y


  1. Step 3 : Install Docker

  • Kubernetes uses Docker as its container runtime. Install Docker on all nodes (master and worker nodes).
sudo apt install -y docker.io
  • Verify that Docker is installed correctly.
docker --version


  1. Step 4 : Install Kubernetes Components

  • Install the Kubernetes components: kubeadm, kubelet, and kubectl on all nodes.

  • Add the Kubernetes apt repository:

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
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

Install the Kubernetes components,

sudo apt update
sudo apt install -y kubelet kubeadm kubectl
  • Hold the packages at their current version to prevent automatic upgrades
sudo apt-mark hold kubelet kubeadm kubectl


  1. Step 5 : Disable Swap

  • Kubernetes requires swap to be disabled. Disable swap on all nodes.
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab


  1. Step 6 : Initialize the Master Node

  • On the master node, initialize the Kubernetes cluster with kubeadm.
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
  • The --pod-network-cidr flag is not always necessary, but whether you need to include it depends on the specific networking solution (CNI, or Container Network Interface) you plan to use in your Kubernetes cluster.

  • CIDR of 10.244.0.0/16. If you plan to use Flannel, you should include the --pod-network-cidr=10.244.0.0/16 flag to ensure that the cluster is configured correctly for the network plugin.

After initialization, you'll see a join command. Copy this command as it will be used to join worker nodes to the cluster.

Copy the last command starts with kubeadm join, we need to join worker nodes. This command need to run in worker nodes.


  1. Step 7 : Configure kubectl for the Master Node

  • Set up the kubeconfig file for the root user on the master node.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

  • Verify the cluster status
kubectl get nodes


  1. Step 8 : Install a Pod Network Add-on on Master node

  • Install a pod network so that your pods can communicate with each other. We'll use Flannel for this example.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

  • Verify that all nodes are up and running
kubectl get nodes


  1. Step 9 : Join Worker Nodes to the Cluster

  • Expose port 6443 in the Security group, so that worker nodes can join the cluster.

  • Edit inbound rules and add port 6443.

  • On each worker node, use the join command obtained from the master node initialization step.

  • Use sudo before the token.

sudo kubeadm join 172.31.20.13:6443 --token 45j27q.bs4aguaa1d78u2nq \
        --discovery-token-ca-cert-hash sha256:5405d5cfd7c4fbc0669f6eba3f152674b08c773d9e0615392f41e99b94d2de9c

  • Verify that the nodes have joined the cluster. Execute following command in master node.
kubectl get nodes

Now, we have created Kubernetes cluster using kubeadm.


  1. Step 10 : Deploy a Test Application

  • Deploy a simple Nginx application to verify that your Kubernetes cluster is working correctly.
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort

  • In this step, we can disable the firewall for temporary or we can add the node port and Nginx ports in firewall

  • Get the NodePort assigned to the Nginx service.

kubectl get svc
kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        25m
nginx        NodePort    10.103.234.56   <none>        80:30811/TCP   5m2s

  • You should be able to access the Nginx application by visiting http://<node-ip>:<node-port> in your web browser.

  • Note: Replace <node-ip> with your worker node and you can get the <node-port>. In the previous command output, the node port is 30811.

http://<node-ip>:<node-port>

  • Allow Node Port in inbound rules of security group.


Connect With Me

Thank you for reading. I hope you were able to understand and learn something new from my blog.

Happy Learning!

LinkedIn | GitHub

More from this blog

Untitled Publication

52 posts