How to Install Kubernetes on Ubuntu Server: Complete Step-by-Step Guide

Kubernetes has become the industry standard for container orchestration and cloud-native infrastructure. Organizations around the world use Kubernetes to deploy, manage, and scale containerized applications efficiently. Fortunately, you don’t need a large data center to start learning Kubernetes. With a few servers and Ubuntu Server, you can build your own Kubernetes cluster at home.

This guide will walk you through the complete installation process of Kubernetes on Ubuntu Server using kubeadm and containerd. By the end of this tutorial, you will have a working Kubernetes cluster ready for hosting applications, learning DevOps practices, and experimenting with cloud-native technologies.

Prerequisites

Before starting, ensure you have the following:

Hardware Requirements

For a basic homelab cluster:

Node TypeCPURAMStorage
Control Plane2 Cores4 GB40 GB SSD
Worker Node2 Cores4 GB40 GB SSD

Recommended cluster:

  • 1 Control Plane Node
  • 2 Worker Nodes
  • Gigabit Ethernet Network

Software Requirements

  • Ubuntu Server 24.04 LTS or Ubuntu Server 22.04 LTS
  • Static IP addresses for all nodes
  • Sudo privileges
  • Internet connection

Example cluster:

HostnameIP Address
k8s-master192.168.1.10
k8s-worker1192.168.1.11
k8s-worker2192.168.1.12

Step 1: Update Ubuntu Server

Run the following command on every node:

sudo apt update && sudo apt upgrade -y

Reboot if necessary:

sudo reboot

Step 2: Configure Hostnames

Master Node:

sudo hostnamectl set-hostname k8s-master

Worker Node 1:

sudo hostnamectl set-hostname k8s-worker1

Worker Node 2:

sudo hostnamectl set-hostname k8s-worker2

Edit the hosts file on all nodes:

sudo nano /etc/hosts

Add:

192.168.1.10 k8s-master
192.168.1.11 k8s-worker1
192.168.1.12 k8s-worker2

Save and exit.


Step 3: Disable Swap

Kubernetes requires swap to be disabled.

Check current swap:

swapon --show

Disable swap:

sudo swapoff -a

Prevent swap from re-enabling after reboot:

sudo sed -i '/ swap / s/^/#/' /etc/fstab

Verify:

free -h

Swap should show as 0B.


Step 4: Load Required Kernel Modules

Create configuration:

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

Load modules:

sudo modprobe overlay
sudo modprobe br_netfilter

Verify:

lsmod | grep br_netfilter

Step 5: Configure Networking Parameters

Create Kubernetes networking configuration:

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

Apply settings:

sudo sysctl --system

Verify:

sysctl net.ipv4.ip_forward

Expected output:

net.ipv4.ip_forward = 1

Step 6: Install Containerd

Update repositories:

sudo apt update

Install containerd:

sudo apt install -y containerd

Generate default configuration:

sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml

Enable Systemd Cgroup Driver:

sudo nano /etc/containerd/config.toml

Find:

SystemdCgroup = false

Change to:

SystemdCgroup = true

Restart containerd:

sudo systemctl restart containerd
sudo systemctl enable containerd

Check status:

sudo systemctl status containerd

Step 7: Install Kubernetes Packages

Install required packages:

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

Download Kubernetes signing key:

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | \
sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

Add repository:

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

Update package list:

sudo apt update

Install Kubernetes tools:

sudo apt install -y kubelet kubeadm kubectl

Prevent automatic upgrades:

sudo apt-mark hold kubelet kubeadm kubectl

Verify:

kubeadm version

Step 8: Initialize the Kubernetes Cluster

Run only on the Control Plane Node:

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

The process may take several minutes.

After completion, copy the join command displayed at the bottom.

Example:

kubeadm join 192.168.1.10:6443 \
--token abcdef.123456789 \
--discovery-token-ca-cert-hash sha256:xxxxxxxx

Save it for later.


Step 9: Configure kubectl

Run as your normal user:

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

Verify:

kubectl get nodes

Initially, the node may show as NotReady.


Step 10: Install a Pod Network

Install Flannel CNI:

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

Wait a few minutes.

Verify:

kubectl get pods -A

Check node status:

kubectl get nodes

Expected:

NAME         STATUS   ROLES
k8s-master   Ready    control-plane

Step 11: Join Worker Nodes

Run the join command generated earlier on each worker node.

Example:

sudo kubeadm join 192.168.1.10:6443 \
--token abcdef.123456789 \
--discovery-token-ca-cert-hash sha256:xxxxxxxx

Repeat on all worker nodes.


Step 12: Verify Cluster Health

On the control plane:

kubectl get nodes

Expected:

NAME          STATUS   ROLES
k8s-master    Ready    control-plane
k8s-worker1   Ready    <none>
k8s-worker2   Ready    <none>

Check system pods:

kubectl get pods -A

All pods should be running.


Deploy Your First Application

Create an NGINX deployment:

kubectl create deployment nginx \
--image=nginx

Expose service:

kubectl expose deployment nginx \
--port=80 \
--type=NodePort

Verify:

kubectl get svc

Open the assigned NodePort in your browser.

You should see the NGINX welcome page.


Useful Kubernetes Commands

View nodes:

kubectl get nodes

View pods:

kubectl get pods -A

View services:

kubectl get svc

Describe node:

kubectl describe node k8s-master

Check cluster info:

kubectl cluster-info

Conclusion

Installing Kubernetes on Ubuntu Server is one of the best ways to learn modern infrastructure management and cloud-native technologies. Using kubeadm and containerd provides a production-like environment that closely resembles what many organizations deploy in real-world scenarios.

Once your cluster is operational, you can begin deploying applications such as Nextcloud, Grafana, Prometheus, Jellyfin, Home Assistant, and GitLab. Over time, you can expand the cluster, implement GitOps workflows, and explore advanced Kubernetes concepts such as ingress controllers, persistent storage, monitoring, and high availability.

For homelab enthusiasts and IT professionals alike, building a Kubernetes cluster at home is an excellent investment in both technical skills and infrastructure knowledge.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *