Categories: TutorialsUbuntu

How to Install Kubernetes on Ubuntu 22.04

Setting up Kubernetes on Ubuntu streamlines your infrastructure, turning it into a robust container orchestration system. With Kubernetes (K8s), you can automate the deployment, scaling, and operation of application containers,

simplifying management for developers and system administrators.

In this article, you will learn how to install and use Kubernetes on Ubuntu. You will see how to create different types of clusters for different purposes. This article will show you how to make your Kubernetes cluster work smoothly.

Step 1:

Refresh Your System: First, refresh your system to make sure all packages are current.

sudo apt-get update

sudo apt-get upgrade -y

Get Docker: Kubernetes needs Docker to run application containers. Get Docker on every machine by executing the command below:

sudo apt-get install docker.io -y

After getting Docker, put your user in the Docker group to use Docker commands without sudo.

sudo usermod -aG docker $USER

Turn Off Swap: Kubernetes needs you to turn off swap on every machine.

sudo swapoff -a

To keep this change, remove any swap lines in /etc/fstab.

Read: Kubernetes Containerization Management For Large Projects

Step 2:

Get the Kubernetes package repository on every machine by running the command:

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

echo “deb http://apt.kubernetes.io/ kubernetes-xenial main” | sudo tee /etc/apt/sources.list.d/kubernetes.list

Now, get kubeadm, kubelet, and kubectl also on every machine via the commands:

sudo apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

Fix their versions to stop automatic updates.

sudo apt-mark hold kubelet kubeadm kubectl

Read: What is Kubernetes and how does it work

Step 3:

To set up the cluster, run kubeadm on the master node.

sudo kubeadm init –pod-network-cidr=192.168.0.0/16 Then, the instructions on the screen will be able to show you how to use your cluster. Usually, you need to run these commands as a normal user.

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

Step 4:

To make your pods talk to each other, you need a pod network add-on on your cluster. Many people use Calico for this. You can install it with:

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Step 5:

You need to use the kubeadm join command to connect worker nodes to your cluster. This command is given to you when the master is done setting up. Run this command on every worker node:

sudo kubeadm join : –token –discovery-token-ca-cert-hash sha256:

Step 6:

Your cluster is working now, so you can deploy apps. You can begin by deploying a simple app using a deployment YAML file:

apiVersion: apps/v1

kind: Deployment

metadata:

name: nginx-deployment

spec:

replicas: 3

selector:

matchLabels:

app: nginx

template:

metadata:

labels:

app: nginx

spec:

containers:

– name: nginx

image: nginx:latest

ports:

– containerPort: 80

To deploy this, run this command: kubectl apply -f .yaml.

Step 7:

Change the size of your applications by changing the replica count in your deployment. Use kubectl, the command-line tool for Kubernetes, to control your cluster resources. Learn how to deploy more advanced applications, install Kubernetes Dashboard for a graphical interface, and think about using Helm for managing packages.

 

The post How to Install Kubernetes on Ubuntu 22.04 appeared first on net2.

Ubuntu Server Admin

Recent Posts

How to avoid package End of Life through backporting

In July 2025, git received CVE-2025-48384, a high vulnerability allowing arbitrary code execution when cloning…

3 days ago

Showcasing open design in action: Loughborough University design students explore open source projects

Last year, we collaborated with two design student teams from Loughborough University in the UK.…

7 days ago

Canonical Ubuntu and Ubuntu Pro now available on AWS European Sovereign Cloud

January 15, 2026 – Canonical, the publisher of Ubuntu and provider of open source security,…

1 week ago

How to install GitLab on Ubuntu 24.04

How to install GitLab on Ubuntu 24.04 will be explained in this blog post with…

1 week ago

How to Set Up OpenVPN Access Server on Ubuntu 24.04 (VM) & Connect Using OpenVPN Connect

Do you know what was always there but has increased multiple times in the last…

2 weeks ago

How to build DORA-ready infrastructure with verifiable provenance and reliable support

The Digital Operational Resilience Act (DORA) came into force across the EU on January 17,…

2 weeks ago