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.

Sponsored

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:

Sponsored

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

Cut data center energy costs with bare metal automation

Data centers are popping up everywhere. With the rapid growth of AI, cloud services, streaming…

20 hours ago

Build the future of *craft: announcing Starcraft Bounties!

Our commitment to building a thriving open source community is stronger than ever. We believe…

20 hours ago

NodeJS 18 LTS EOL extended from April 2025 to May 2032 on Ubuntu

The clock was ticking: Node.js 18’s upstream End of Life (EOL) The OpenJS Foundation is…

20 hours ago

Native integration now available for Pure Storage and Canonical LXD

June 25th, 2025 – Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer…

2 days ago

Revolutionizing Web Page Creation: How Structured Content is Slashing Design and Development Time

Co-authored with Julie Muzina A year ago, during our Madrid Engineering Sprint, we challenged ourselves…

3 days ago

Ubuntu Weekly Newsletter Issue 897

Welcome to the Ubuntu Weekly Newsletter, Issue 897 for the week of June 15 –…

4 days ago