NeuronVM bread crumb arrow icon Docs bread crumb arrow icon How to Install Kubernetes on Ubuntu 22.04

How to Install Kubernetes on Ubuntu 22.04

How to Install Kubernetes on Ubuntu 22.04
Eileen.B
4m
0 comments
Print
2026/05/24

Installing Kubernetes may seem complicated at first sight, but if you follow our steps correctly and in order, the process is quite manageable, in this tutorial, you will learn step by step how to set up a Kubernetes cluster on Ubuntu 22.04, with one node acting as the Master and two other nodes as Workers, this guide is written in a very practical way and is suitable for people who want to actually run and test Kubernetes, not just read about it.

Prerequisites

Before you begin, make sure you have the following:

  • At least 2 servers running Ubuntu 24.04
  • (one Master node and at least one Worker node, we’ll use two Workers in this tutorial)
  • SSH access to all nodes with a user with sudo privileges
  • At least 2GB of RAM and 2 vCPUs per node
  • At least 20GB of free disk space

Step 1: Set up hostname and hosts file (on all nodes)

The first thing you need to do is to make sure that the cluster nodes can identify each other by name and not just by IP, this will make communication between the nodes way easier, on all nodes, open the following file:

sudo nano /etc/hosts

Add the IP and hostname of each node (make sure to replace the IPs with the actual values ​​of your server):

192.168.1.10 k8s-master-node

192.168.1.11 k8s-worker-node-1

192.168.1.12 k8s-worker-node-2

 

 

Set up hostname

Save the file and exit, now, set each node to its own hostname:

On the master node

sudo hostnamectl set-hostname k8s-master-node

On the first worker node

sudo hostnamectl set-hostname k8s-worker-node-1

On the second worker node

sudo hostnamectl set-hostname k8s-worker-node-2

To apply the changes, run this command:

sudo exec bash

Finally, make sure all nodes can see each other with the following command:

ping k8s-worker-node-1

ping k8s-worker-node-2

Step 2: Disable Swap (on all nodes)

Kubernetes does not require swap for stable operation, and having it enabled can cause disruption.

Temporarily disable:

sudo swapoff -a

To disable permanently, open the /etc/fstab file and comment out the swap line.

Check the status:

swapon --show

If no output is displayed, swap is disabled.

sudo swapoff -a

Step 3: Load Containerd Modules (on all nodes)

Kubernetes requires a runtime to manage containers, and containerd is the default choice.

Load the required modules:

sudo modprobe overlay
sudo modprobe br_netfilter

To make it permanent:

sudo tee /etc/modules-load.d/k8s.conf <<EOF
overlay
br_netfilter
EOF

Load modules

Step 4: Configure IPv4 Networking for Kubernetes 

Networking is essential for pods to communicate with each other and with the outside world.

Create the configuration file:

sudo nano /etc/sysctl.d/k8s.conf

and add these lines:

net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1

Apply the configuration:

sudo sysctl --system

Step 5: Install Docker and Configure Containerd

Docker is responsible for running containers, and Kubernetes manages them.

Install Docker:

sudo apt update
sudo apt install docker.io -y

Enable Docker at boot time:

sudo systemctl enable docker

Configure containerd:

sudo mkdir /etc/containerd
sudo 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 6: Install Kubernetes components

Prerequisites:

sudo apt install curl ca-certificates apt-transport-https -y

Add Kubernetes repository:

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/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.31/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update

Install tools:

sudo apt install kubelet kubeadm kubectl -y

Step 7: Start the cluster 

On the master node, run:

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

Then set the user permissions:

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

Step 8: Install the Calico network plugin

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/tigera-operator.yaml
curl -O https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/custom-resources.yaml
sed -i 's/192.168.0.0\/16/10.10.0.0\/16/' custom-resources.yaml
kubectl create -f custom-resources.yaml

Step 9: Add Worker Nodes

Run the kubeadm join command created in Step 7 on each Worker.

After that, check on the Master:

kubectl get nodes

Step 10: Testing the Kubernetes Cluster

Create a namespace:

kubectl create namespace demo-namespace

Create a deployment:

kubectl create deployment my-app --image=nginx --replicas=2 -n demo-namespace

Expose the service:

kubectl expose deployment my-app -n demo-namespace --type NodePort --port 80

Finally, you can test access with the IP of one of the Workers.

My Experience with Installing Kubernetes on Ubuntu 22.04

In my experience setting up this cluster, the most time-consuming part was the initial preparation of the nodes, specifically setting up hostnames and synchronizing network settings. If these steps are not done carefully, Kubernetes will give misleading errors in the later steps that take time to figure out. The important thing I found was that using containerd with SystemdCgroup enabled the cluster to run more stably and come up without any problems after rebooting the nodes. Calico also set up the pod network very quickly and without any problems, and communication between the nodes was quite smooth. If you are installing Kubernetes for the first time, I recommend doing a simple check after each step and not rushing, this will prevent most errors.

Conclusion

Setting up Kubernetes on Ubuntu 22.04 may seem complicated at first, but once you follow our steps step by step, it is quite easy, in this tutorial, we saw how to create a real cluster with a Master and several Workers, set up the network, and finally run a sample application on it. After successfully completing these steps, you have a ready-made cluster on which you can deploy services, microservices, and even real test and development environments, from here on, learning Kubernetes becomes more practical, and you can always check for more tutorials on our website.

Share this Post
How useful was this post for you?
0 Points from 0 votes
Frequently Asked Questions

Kubernetes is not compatible with Swap for better resource management and enabling it can cause errors.

At least two Ubuntu servers, each with 2GB of RAM and 2 CPU cores.

Eileen.B

Leave a reply

Calculate the value of (2 + 2) :

Save my name and email in this browser for the next time.

Last Comments

Show More
© Copyright 2025 NeuronVM.
Use of this Site is subject to express terms of use