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.
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:
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:
In this tutorial, “kubernetes-master-1.heyvaldemar.net” is used as the name of the server with the Master role.
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:
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.
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:
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.
Restart the hostamed service for the server name changes to take effect using the command:
Check the correctness of the server name using the command:
Now let’s replace the current shell process with the new one using the command:
Next, you need to disable the paging file using the command:
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:
Load the kernel modules with the command:
Load the “overlay” module with the command:
Load the “br_netfilter” module with the command:
Set the kernel options for Kubernetes with the command:
Apply the changes made using the command:
Now let’s add the official Docker key with the command:
Next, we connect the Docker repository using the command:
We press the “Enter” button.
Update the local package index to the latest changes in the repositories using the command:
Now let’s install the packages required for Kubernetes to work using the command:
Now you need to configure containerd.
containerd - an industry-standard container runtime with an emphasis on simplicity, robustness and portability
We execute the command:
We execute the command:
Restart containerd to apply the changes, using the command:
We enable autostart of the containerd service at the start of the operating system using the command:
Now let’s add the official Kubernetes key using the command:
Next, we connect the Kubernetes repository using the command:
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”.
We press the “Enter” button.
Update the local package index to the latest changes in the repositories using the command:
Now install the kubelet, kubeadm and kubectl packages using the command:
The next step is to disable automatic updates and removal of installed packages using the command:
Now you need to start the initialization of the Kubernetes cluster using the command:
In this tutorial, “kubernetes-master-1.heyvaldemar.net” is used as the name of the server with the Master role.
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:
We execute the command:
We execute the command:
Next, you can see the addresses of the master and services using the command:
Now you can see a list of all nodes in the cluster and the status of each node using the command:
We connect to the server on which we plan to install the Kubernetes Worker role.
Assign a name to the server using the command:
This tutorial uses “kubernetes-worker-1.heyvaldemar.net” as the name of the server with the Worker role.
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:
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.
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:
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.
Restart the hostamed service for the server name changes to take effect using the command:
Check the correctness of the server name using the command:
Now let’s replace the current shell process with the new one using the command:
Next, you need to disable the paging file using the command:
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:
Load the kernel modules with the command:
Load the “overlay” module with the command:
Load the “br_netfilter” module with the command:
Set the kernel options for Kubernetes with the command:
Apply the changes made using the command:
Now let’s add the official Docker key with the command:
Next, we connect the Docker repository using the command:
We press the “Enter” button.
Update the local package index to the latest changes in the repositories using the command:
Now let’s install the packages required for Kubernetes to work using the command:
Now you need to configure containerd.
containerd - an industry-standard container runtime with an emphasis on simplicity, robustness and portability
We execute the command:
We execute the command:
Restart containerd to apply the changes, using the command:
We enable autostart of the containerd service at the start of the operating system using the command:
Now let’s add the official Kubernetes key using the command:
Next, we connect the Kubernetes repository using the command:
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”.
We press the “Enter” button.
Update the local package index to the latest changes in the repositories using the command:
Now install the kubelet, kubeadm and kubectl packages using the command:
The next step is to disable automatic updates and removal of installed packages using the command:
Next, you need to add a server with the Worker role to the Kubernetes cluster using the command:
The server with the Worker role has successfully joined the Kubernetes cluster.
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:
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:
Install Calico with the command:
Check the status of the pods in the kube-system namespace with the command:
Now you can see a list of all nodes in the cluster and the status of each node using the command:
The nodes are in the “Ready” status and the Kubernetes cluster is ready to go.
My Courses
🎓 Dive into my comprehensive IT courses designed for enthusiasts and professionals alike. Whether you’re looking to master Docker, conquer Kubernetes, or advance your DevOps skills, my courses provide a structured pathway to enhancing your technical prowess.
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 My Coffee Supplies
💖 PayPal
🏆 Patreon
💎 GitHub
🥤 BuyMeaCoffee
🍪 Ko-fi
Follow Me
🎬 YouTube
🐦 Twitter
🎨 Instagram
🐘 Mastodon
🧵 Threads
🎸 Facebook
🧊 Bluesky
🎥 TikTok
💻 LinkedIn
📣 daily.dev Squad
🧩 LeetCode
🐈 GitHub
Is this content AI-generated?
Nope! Each article is crafted by me, fueled by a deep passion for Docker and decades of IT expertise. While I employ AI to refine the grammar—ensuring the technical details are conveyed clearly—the insights, strategies, and guidance are purely my own. This approach may occasionally activate AI detectors, but you can be certain that the underlying knowledge and experiences are authentically mine.