Dev ❤ Ops

How to Install Kubernetes 1.27

How to Install Kubernetes 1.27

This article talks about how to install Kubernetes 1.27 on Ubuntu VM but the same also can be followed for other Linux distributions. Some of the OS-specific commands can be different for the other Linux distribution like RHEL.

Here is a step-by-step detailed process to install Kubernetes 1.27 with Kubeadm on Ubuntu 20.04. or higher. Please note that the process might be slightly different depending on your Linux distribution.

Step 1: Prepare the Environment

Update your system packages:

sudo apt-get update
sudo apt-get upgrade -y

Install required packages:

sudo apt-gt install -y apt-transport-https ca-certificates curl

Disable swap:

sudo swapoff -a

To make this change permanent, edit /etc/fstab and comment out the swap line:

sudo nano /etc/fstab

Find the line that looks like this:

UUID=xxxx-xxxx-xxxx-xxxx none swap sw 0 0

And comment it out by adding a # at the beginning of the line:

# UUID=xxxx-xxxx-xxxx-xxxx none swap sw 0 0

Save and exit the file.

You can also check: How to Disable Swap

Step 2: Install Container Engine

Add required environment variables:

export OS_VERSION_ID=xUbuntu_$(cat /etc/os-release | grep VERSION_ID | awk -F"=" '{print $2}' | tr -d '"')
export CRIO_VERSION=1.25

Add repository:

echo "deb$OS_VERSION_ID/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
echo "deb$CRIO_VERSION/$OS_VERSION_ID/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION.list

curl -L$CRIO_VERSION/$OS_VERSION_ID/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add -
curl -L$OS_VERSION_ID/Release.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/libcontainers.gpg add -

Update package index and install Cri-o:

sudo apt-get update
sudo apt-get install cri-o cri-o-runc cri-tools -y

Enable and start Cri-o:

sudo systemctl daemon-reload
sudo systemctl enable crio --now

Step 3: Install Kubernetes Components (kubeadm, kubelet, kubectl)

Add Kubernetes repository:

curl -s | sudo apt-key add -
echo "deb kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Update package index and install Kubernetes components:

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl

Hold these packages to prevent unintentional updates:

sudo apt-mark hold kubelet kubeadm kubectl

Step 4: Initialize the Kubernetes Control-Plane Node

Run the following command on the control-plane node:

sudo kubeadm init --pod-network-cidr= --kubernetes-version 1.27.0

Take note of the Kubeadm join command with the token and hash that is displayed at the end of the output.

Configure Kubectl for the current user:

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

Step 5: Set Up a Pod Network

In this example, we’ll use Calico as the pod network. You can choose another one if you prefer.

kubectl apply -f

Step 6: Join Worker Nodes in the Cluster

On each worker node, run the Kubeadm join command that was displayed at the end of the Kubeadm init output on the control-plane node. The command should look similar to this:

sudo kubeadm join <control-plane-ip>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash <hash>

Replace control-plane-ip, control-plane-port, token, and hash with the actual values from your Kubeadm init output.

Step 7: Verify the Cluster

On the control-plane node, check the status of your nodes by running:

kubectl get nodes

Initially, the worker nodes may show a NotReady status. After a few moments, they should transition to the Ready state, indicating that they are part of the cluster and functioning properly.

Step 8: Deploy a Sample Application (Optional)

To test your Kubernetes cluster, you can deploy a sample application. In this example, we’ll deploy a simple Nginx deployment:

Create an Nginx deployment:

kubectl create deployment nginx --image=nginx

Expose the Nginx deployment as a service:

kubectl expose deployment nginx --port=80 --type=LoadBalancer

Check the status of the deployed resources:

kubectl get deployments
kubectl get services

You should see the Nginx deployment and service listed. The service should show an external IP after a few moments, which you can use to access the Nginx application.

That’s it! You now have a working Kubernetes 1.27 cluster set up using Kubeadm.

These steps provide an overview of setting up Kubernetes 1.27 with Kubeadm. For more detailed instructions and troubleshooting tips, refer to the official Kubernetes documentation:

Follow us on LinkedIn for updates!

Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “How to Install Kubernetes 1.27”