2729 words
14 minutes

Install Kubernetes on Ubuntu Server 22.04 LTS

Cover image for Install Kubernetes on Ubuntu Server 22.04 LTS

This article is for those looking for a detailed and straightforward guide on installing Kubernetes on Ubuntu Server 22.04 LTS.

Kubernetes is an open-source container orchestration system for automating software deployment, scaling, and management.

IMPORTANT

OpenSSH must be installed on the server, and port 22 must be open in order to be able to connect to the server using the SSH protocol.

To install OpenSSH on a server, you can use the command:

Terminal window
sudo apt install openssh-server
NOTE

To connect to the server from a Windows system, you can use tools like PuTTY or MobaXterm.

NOTE

This guide walks you through connecting to a server with the iTerm2 terminal emulator on macOS.

CAUTION

You will need to open the following TCP ports for access to the services:

Kubernetes Master (Control Plane):

  • TCP port 6443 - for the Kubernetes API to work.
  • TCP port 2379-2380 - for the etcd server client API to work.
  • TCP port 10250 - for the Kubelet API to work.
  • TCP port 10259 - for kube-scheduler to work.
  • TCP port 10257 - for kube-controller-manager to work.

Kubernetes Worker:

  • TCP port 0250 - for the Kubelet API to work.
  • TCP port 30000-32767 - for NodePort Services to work.
IMPORTANT

We will consider installing one server with the Master role and one server with the Worker role. In the future, you can independently add the required number of servers to ensure high availability.

We connect to the server on which we plan to install the Kubernetes Master role.

Assign a name to the server using the command:

Terminal window
sudo hostnamectl set-hostname kubernetes-master-1.heyvaldemar.net
NOTE

In this tutorial, kubernetes-master-1.heyvaldemar.net is used as the name of the server with the Master role.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 1

The server with the Worker role must resolve the name of the server with the Master role, and also the server with the Master role must resolve the name of the server with the Worker role.

Next, add the IP address and name of the server with the Master role to the “/etc/hosts” file using the command:

Terminal window
echo "10.0.5.140 kubernetes-master-1.heyvaldemar.net kubernetes-master-1" | sudo tee -a /etc/hosts

Having this entry will allow the server with the agent installed to resolve the Kubernetes server name even without a DNS entry.

NOTE

In this guide, the server name with the Master role is kubernetes-master-1.heyvaldemar.net, and the IP address is 10.0.5.140.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 2

Make sure that the name of the server with the Worker role has the correct DNS entry, and also update the “/etc/hosts” file on the server with the command:

Terminal window
echo "10.0.6.19 kubernetes-worker-1.heyvaldemar.net kubernetes-worker-1" | sudo tee -a /etc/hosts

Having this entry will allow the server with the agent installed to resolve the Kubernetes server name even without a DNS entry.

NOTE

In this guide, the Master server name is kubernetes-worker-1.heyvaldemar.net and the IP address is 10.0.6.19.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 3

Restart the hostamed service for the server name changes to take effect using the command:

Terminal window
sudo systemctl restart systemd-hostnamed

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 4

Check the correctness of the server name using the command:

Terminal window
hostname

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 5

Now let’s replace the current shell process with the new one using the command:

Terminal window
exec bash

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 6

Next, you need to disable the paging file using the command:

Terminal window
sudo swapoff -a

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 7

The command above disables the swap file until the system is rebooted. We have to make sure that it stays off even after a reboot. To do this, edit the “fstab” file by commenting out the “/swapfile” line with the ”#” symbol.

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 8

Load the kernel modules with the command:

Terminal window
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 9

Load the “overlay” module with the command:

Terminal window
sudo modprobe overlay

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 10

Load the “br_netfilter” module with the command:

Terminal window
sudo modprobe br_netfilter

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 11

Set the kernel options for Kubernetes with the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 12

Apply the changes made using the command:

Terminal window
sudo sysctl --system

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 13

Now let’s add the official Docker key with the command:

Terminal window
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 14

Next, we connect the Docker repository using the command:

Terminal window
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 15

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 16

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 17

Now let’s install the packages required for Kubernetes to work using the command:

Terminal window
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates containerd.io

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 18

Now you need to configure containerd.

containerd - an industry-standard container runtime with an emphasis on simplicity, robustness and portability

We execute the command:

Terminal window
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 19

We execute the command:

Terminal window
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 20

Restart containerd to apply the changes, using the command:

Terminal window
sudo systemctl restart containerd

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 21

We enable autostart of the containerd service at the start of the operating system using the command:

Terminal window
sudo systemctl enable containerd

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 22

Now let’s add the official Kubernetes key using the command:

Terminal window
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 23

Next, we connect the Kubernetes repository using the command:

Terminal window
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
NOTE

At the time of writing this guide, Xenial is the current Kubernetes repository, but when the repository is available for Ubuntu 22.04 (Jammy Jellyfish), you will need to change the word in the command above from “xenial” to “jammy”.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 24

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 25

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 26

Now install the kubelet, kubeadm and kubectl packages using the command:

Terminal window
sudo apt install -y kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 27

The next step is to disable automatic updates and removal of installed packages using the command:

Terminal window
sudo apt-mark hold kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 28

Now you need to start the initialization of the Kubernetes cluster using the command:

Terminal window
sudo kubeadm init --control-plane-endpoint=kubernetes-master-1.heyvaldemar.net
NOTE

In this tutorial, kubernetes-master-1.heyvaldemar.net is used as the name of the server with the Master role.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 29

NOTE

To add another server to the cluster, you will need to do the same work of installing and configuring the server, and then run the kubeadm join command with the appropriate token for the server with the Master or Worker role.

Next, you need to run a few commands to start interacting with the cluster.

We execute the command:

Terminal window
mkdir -p $HOME/.kube

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 30

We execute the command:

Terminal window
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 31

We execute the command:

Terminal window
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 32

Next, you can see the addresses of the master and services using the command:

Terminal window
kubectl cluster-info

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 33

Now you can see a list of all nodes in the cluster and the status of each node using the command:

Terminal window
kubectl get nodes

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 34

We connect to the server on which we plan to install the Kubernetes Worker role.

Assign a name to the server using the command:

Terminal window
sudo hostnamectl set-hostname kubernetes-worker-1.heyvaldemar.net

This tutorial uses kubernetes-worker-1.heyvaldemar.net as the name of the server with the Worker role.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 35

The server with the Worker role must resolve the name of the server with the Master role, and also the server with the Master role must resolve the name of the server with the Worker role.

Next, add the IP address and name of the server with the Master role to the “/etc/hosts” file using the command:

Terminal window
echo "10.0.6.19 kubernetes-worker-1.heyvaldemar.net kubernetes-worker-1" | sudo tee -a /etc/hosts

Having this entry will allow the server with the agent installed to resolve the Kubernetes server name even without a DNS entry.

NOTE

In this guide, the Master server name is kubernetes-worker-1.heyvaldemar.net and the IP address is 10.0.6.19.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 36

Make sure that the name of the server with the Worker role has the correct DNS entry, and also update the “/etc/hosts” file on the server with the command:

Terminal window
echo "10.0.5.140 kubernetes-master-1.heyvaldemar.net kubernetes-master-1" | sudo tee -a /etc/hosts

Having this entry will allow the server with the agent installed to resolve the Kubernetes server name even without a DNS entry.

NOTE

In this guide, the server name with the Master role is kubernetes-master-1.heyvaldemar.net, and the IP address is 10.0.5.140.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 37

Restart the hostamed service for the server name changes to take effect using the command:

Terminal window
sudo systemctl restart systemd-hostnamed

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 38

Check the correctness of the server name using the command:

Terminal window
hostname

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 39

Now let’s replace the current shell process with the new one using the command:

Terminal window
exec bash

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 40

Next, you need to disable the paging file using the command:

Terminal window
sudo swapoff -a

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 41

The command above disables the swap file until the system is rebooted. We have to make sure that it stays off even after a reboot. To do this, edit the “fstab” file by commenting out the “/swapfile” line with the ”#” symbol.

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 42

Load the kernel modules with the command:

Terminal window
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 43

Load the “overlay” module with the command:

Terminal window
sudo modprobe overlay

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 44

Load the “br_netfilter” module with the command:

Terminal window
sudo modprobe br_netfilter

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 45

Set the kernel options for Kubernetes with the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 46

Apply the changes made using the command:

Terminal window
sudo sysctl --system

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 47

Now let’s add the official Docker key with the command:

Terminal window
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 48

Next, we connect the Docker repository using the command:

Terminal window
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 49

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 50

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 51

Now let’s install the packages required for Kubernetes to work using the command:

Terminal window
sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates containerd.io

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 52

Now you need to configure containerd.

containerd - an industry-standard container runtime with an emphasis on simplicity, robustness and portability

We execute the command:

Terminal window
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 53

We execute the command:

Terminal window
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 54

Restart containerd to apply the changes, using the command:

Terminal window
sudo systemctl restart containerd

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 55

We enable autostart of the containerd service at the start of the operating system using the command:

Terminal window
sudo systemctl enable containerd

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 56

Now let’s add the official Kubernetes key using the command:

Terminal window
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 57

Next, we connect the Kubernetes repository using the command:

Terminal window
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
NOTE

At the time of writing this guide, Xenial is the current Kubernetes repository, but when the repository is available for Ubuntu 22.04 (Jammy Jellyfish), you will need to change the word in the command above from “xenial” to “jammy”.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 58

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 59

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 60

Now install the kubelet, kubeadm and kubectl packages using the command:

Terminal window
sudo apt install -y kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 61

The next step is to disable automatic updates and removal of installed packages using the command:

Terminal window
sudo apt-mark hold kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 62

Next, you need to add a server with the Worker role to the Kubernetes cluster using the command:

Terminal window
sudo kubeadm join kubernetes-master-1.heyvaldemar.net:6443 --token 5xuqag.tefxcfleieexwbos \
--discovery-token-ca-cert-hash sha256:8c3e8eb9d95cd16496db9f65956e2ce1c2164fa64d17a487374bd906dbc0dcb3

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 63

The server with the Worker role has successfully joined the Kubernetes cluster.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 64

We return to the server with the Kubernetes Master role.

Now you can see a list of all nodes in the cluster and the status of each node using the command:

Terminal window
kubectl get nodes

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 65

The nodes are in the “NotReady” status. To fix this, you need to install CNI (Container Network Interface) or network add-ons such as Calico, Flannel and Weave-net.

Download the Calico manifest with the command:

Terminal window
curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 66

Install Calico with the command:

Terminal window
kubectl apply -f calico.yaml

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 67

Check the status of the pods in the kube-system namespace with the command:

Terminal window
kubectl get pods -n kube-system

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 68

Now you can see a list of all nodes in the cluster and the status of each node using the command:

Terminal window
kubectl get nodes

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 69

The nodes are in the “Ready” status and the Kubernetes cluster is ready to go.

Install Kubernetes on Ubuntu Server 22.04 LTS - Step 70


Patreon Exclusives#

🏆 Join my Patreon and dive deep into the world of Docker and DevOps with exclusive content tailored for IT enthusiasts and professionals. As your experienced guide, I offer a range of membership tiers designed to suit everyone from newbies to IT experts.


Tools I Personally Trust#

If you’re building things, breaking things, and trying to keep your digital life a little saner (like every good DevOps engineer), these are two tools that I trust and use daily:

🛸 Proton VPN - My shield on the internet. It keeps your Wi-Fi secure, hides your IP, and blocks those creepy trackers. Even if I’m hacking away on free café Wi-Fi, I know I’m safe.

🔑 Proton Pass - My password vault. Proper on-device encryption, 2FA codes, logins, secrets - all mine and only mine. No compromises.

These are partner links - you won’t pay a cent more, but you’ll be supporting DevOps Compass. Thanks a ton - it helps me keep this compass pointing the right way 💜


Gear & Books I Trust#

📕 Essential DevOps books
🖥️ Studio streaming & recording kit
📡 Streaming starter kit


Social Channels#

🎬 YouTube
🐦 X (Twitter)
🎨 Instagram
🐘 Mastodon
🧵 Threads
🎸 Facebook
🦋 Bluesky
🎥 TikTok
💻 LinkedIn
📣 daily.dev Squad
✈️ Telegram
🐈 GitHub


Community of IT Experts#

👾 Discord


Refill My Coffee Supplies#

💖 PayPal
🏆 Patreon
🥤 BuyMeaCoffee
🍪 Ko-fi
💎 GitHub
Telegram Boost

🌟 Bitcoin (BTC): bc1q2fq0k2lvdythdrj4ep20metjwnjuf7wccpckxc
🔹 Ethereum (ETH): 0x76C936F9366Fad39769CA5285b0Af1d975adacB8
🪙 Binance Coin (BNB): bnb1xnn6gg63lr2dgufngfr0lkq39kz8qltjt2v2g6
💠 Litecoin (LTC): LMGrhx8Jsx73h1pWY9FE8GB46nBytjvz8g


Is this content AI-generated?

No. Every article on this blog is written by me personally, drawing on decades of hands-on IT experience and a genuine passion for technology.

I use AI tools exclusively to help polish grammar and ensure my technical guidance is as clear as possible. However, the core ideas, strategic insights, and step-by-step solutions are entirely my own, born from real-world work.

Because of this human-and-AI partnership, some detection tools might flag this content. You can be confident, though, that the expertise is authentic. My goal is to share road-tested knowledge you can trust.

Install Kubernetes on Ubuntu Server 22.04 LTS
https://www.heyvaldemar.com/install-kubernetes-on-ubuntu-server-22-04-lts/
Author
Vladimir Mikhalev
Published at
2022-09-09
License
CC BY-NC-SA 4.0