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.

In this guide, we will consider the case when you already have a server with the Ubuntu Server 22.04 LTS operating system installed on it.

You can read more about how to install Ubuntu Server 22.04 LTS in my guide “Install Ubuntu Server 22.04 LTS”.

In addition, 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:

sudo apt install openssh-server

If you plan to connect to the server using the Windows operating system, you can use PuTTY or MobaXterm.

This guide describes how to connect to a server using the iTerm2 terminal emulator installed on the macOS operating system.

Please note that you will need to open the following TCP ports to access your server:

Kubernetes Master (Control Plane):

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

Kubernetes Worker:

  • TCP порт 0250 - for the Kubelet API to work.
  • TCP порт 30000-32767 - for NodePort Services to work.

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:

sudo hostnamectl set-hostname kubernetes-master-1.heyvaldemar.net

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

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:

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.

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

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:

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.

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

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

sudo systemctl restart systemd-hostnamed

Install Kubernetes on Ubuntu Server 22.04 LTS

Check the correctness of the server name using the command:

hostname

Install Kubernetes on Ubuntu Server 22.04 LTS

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

exec bash

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo swapoff -a

Install Kubernetes on Ubuntu Server 22.04 LTS

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:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Load the kernel modules with the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Load the “overlay” module with the command:

sudo modprobe overlay

Install Kubernetes on Ubuntu Server 22.04 LTS

Load the “br_netfilter” module with the command:

sudo modprobe br_netfilter

Install Kubernetes on Ubuntu Server 22.04 LTS

Set the kernel options for Kubernetes with the command:

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

Apply the changes made using the command:

sudo sysctl --system

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

Next, we connect the Docker repository using the command:

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

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Now you need to configure containerd.

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

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Restart containerd to apply the changes, using the command:

sudo systemctl restart containerd

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo systemctl enable containerd

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Next, we connect the Kubernetes repository using the command:

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

Please note that 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

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt install -y kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt-mark hold kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

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

Please note that 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:

mkdir -p $HOME/.kube

Install Kubernetes on Ubuntu Server 22.04 LTS

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

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

kubectl cluster-info

Install Kubernetes on Ubuntu Server 22.04 LTS

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

kubectl get nodes

Install Kubernetes on Ubuntu Server 22.04 LTS

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

Assign a name to the server using the command:

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

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:

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.

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

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:

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.

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

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

sudo systemctl restart systemd-hostnamed

Install Kubernetes on Ubuntu Server 22.04 LTS

Check the correctness of the server name using the command:

hostname

Install Kubernetes on Ubuntu Server 22.04 LTS

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

exec bash

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo swapoff -a

Install Kubernetes on Ubuntu Server 22.04 LTS

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:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Load the kernel modules with the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Load the “overlay” module with the command:

sudo modprobe overlay

Install Kubernetes on Ubuntu Server 22.04 LTS

Load the “br_netfilter” module with the command:

sudo modprobe br_netfilter

Install Kubernetes on Ubuntu Server 22.04 LTS

Set the kernel options for Kubernetes with the command:

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

Apply the changes made using the command:

sudo sysctl --system

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

Next, we connect the Docker repository using the command:

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

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Now you need to configure containerd.

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

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

We execute the command:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Restart containerd to apply the changes, using the command:

sudo systemctl restart containerd

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo systemctl enable containerd

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Next, we connect the Kubernetes repository using the command:

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

Please note that 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

We press the “Enter” button.

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt update

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt install -y kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS

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

sudo apt-mark hold kubelet kubeadm kubectl

Install Kubernetes on Ubuntu Server 22.04 LTS

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

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

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

Install Kubernetes on Ubuntu Server 22.04 LTS

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:

kubectl get nodes

Install Kubernetes on Ubuntu Server 22.04 LTS

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:

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

Install Kubernetes on Ubuntu Server 22.04 LTS

Install Calico with the command:

kubectl apply -f calico.yaml

Install Kubernetes on Ubuntu Server 22.04 LTS

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

kubectl get pods -n kube-system

Install Kubernetes on Ubuntu Server 22.04 LTS

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

kubectl get nodes

Install Kubernetes on Ubuntu Server 22.04 LTS

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

Install Kubernetes on Ubuntu Server 22.04 LTS

My Services

💼 Take a look at my service catalog and find out how we can make your technological life better. Whether it’s increasing the efficiency of your IT infrastructure, advancing your career, or expanding your technological horizons — I’m here to help you achieve your goals. From DevOps transformations to building gaming computers — let’s make your technology unparalleled!

Refill the Author’s Coffee Supplies

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

Vladimir Mikhalev
I’m Vladimir Mikhalev, the Docker Captain, but my friends can call me Valdemar.

DevOps Community

hey 👋 If you have questions about installation or configuration, then ask me and members of our community: