How to Install and Deploy Kubernetes on AlmaLinux

Kubernetes, often abbreviated as K8s, is an open-source platform designed to automate deploying, scaling, and operating application containers. It provides a platform for orchestrating and managing containerized workloads across a cluster of machines.

Whether you are new to Kubernetes or looking to migrate from another orchestration platform, this article will cover the steps to install and deploy Kubernetes on AlmaLinux a robust enterprise Linux distribution.

Prerequisites

Before you begin to install Kubernetes on AlmaLinux 9 make sure you have the following:

  1. AlmaLinux is installed on your machines.
  2. At least one master node and one or more worker nodes.
  3. Root or sudo access on these machines.

Setting Up Kubernetes on AlmaLinux

Following are the steps described below to install and deploy Kubernetes on AlmaLinux:

Step 1: Update System

First, it’s essential to update your system to ensure all packages are up-to-date. Use the following command:

sudo dnf update -y
dnf update

Step 2: Install Docker

Kubernetes uses Docker to manage containers. Install Docker using the following commands:

sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io -y
setup docker

Start Docker and enable it to start on boot:

sudo systemctl start docker
sudo systemctl enable docker
start docker

Verify the Docker installation:

docker --version
docker version

Step 3: Disable SELinux

SELinux can interfere with Kubernetes operations. Disable it by modifying the SELinux configuration file:

sudo setenforce 0 && sudo sed -i --follow-symlinks 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux

Step 4: Disable Swap

Kubernetes requires swap to be disabled. Turn off the swap using the following commands:

sudo swapoff -a && sudo sed -i '/swap/d' /etc/fstab

Step 5: Install Kubernetes Packages

Add the Kubernetes repository:

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

Install Kubernetes packages:

sudo dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

Start and enable kubelet:

sudo systemctl enable --now kubelet

Step 6: Configure sysctl

Configure sysctl for Kubernetes networking:

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

Apply the configuration:

sudo sysctl --system

Step 7: Initialize Master Node

On the master node, initialize Kubernetes:

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

Set up the kubeconfig file for the root 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 8: Install Pod Network

Kubernetes requires a pod network add-on for communication between cluster nodes. We will use Calico as an example:

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

Step 9: Join Worker Nodes to Cluster

On each worker node, use the command provided by the kubeadm init output to join the cluster. This command will look something like this:

sudo kubeadm join <master-node-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>

You can find the join command again by running the following on the master node:

kubeadm token create --print-join-command

Step 10: Verify Cluster

On the master node, verify that all nodes are part of the cluster:

kubectl get nodes

You should see both the master and worker nodes listed.

Step 11: Deploy Test Application

To ensure that everything is set up correctly, deploy a simple test application. For example, deploy the Apache or Nginx web server:

kubectl create deployment nginx --image=nginx && kubectl expose deployment nginx --port=80 --type=NodePort

Verify the deployment:

kubectl get pods && kubectl get svc

You should see the Nginx pod running and the service exposing it.

Conclusion

We have successfully installed and deployed Kubernetes on AlmaLinux. From here, we can explore more advanced Kubernetes features, such as deploying multi-container applications, managing storage, and setting up continuous deployment pipelines. Kubernetes is a powerful tool and with AlmaLinux we have a solid foundation for scalable and reliable container orchestration.

Discover a seamless KVM VPS server that helps to install Kubernetes where reliability converges with security. Ultahost ensures efficient server management and dedicates resources to guarantee optimal speed and stability. Elevate your online presence with us.

FAQ

What is Kubernetes?
Why use AlmaLinux for Kubernetes?
What are prerequisites for installing Kubernetes on AlmaLinux?
How do I install Kubernetes on AlmaLinux?
What is kubeadm, and why is it used?
Can I use AlmaLinux for production Kubernetes clusters?
How do I troubleshoot Kubernetes installation issues on AlmaLinux?

Related Post

How to Set Docker Environment Variables

Docker has revolutionized how we build, deploy, and run...

How to Install Objective-C on Linux

Objective-C is a powerful programming language often as...

How to Use Linux SS (Socket Statistics) Comma

The ss (Socket Statistics) command is a modern Linux ut...

How to Use DD Show Progress Command in Linux

The dd command in Linux is a versatile utility widely u...

How to Find and Replace in Vim and Vi

Vim and Vi are two of the most popular text editors in ...

How to Install Rancher on CentOS 7

Rancher is an open-source platform that simplifies the ...

Leave a Comment