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.

See also  RSpec story about disappearing classes

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

See also  How to display Graphics card information on Ubuntu 22.04

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

Sponsored

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.

Leave a Comment