CentOSRHEL Based

How To Install Kubernetes on CentOS Stream 10

Install Kubernetes on CentOS Stream 10

In this tutorial, we will show you how to install Kubernetes on CentOS Stream 10. Kubernetes has become the de facto standard for container orchestration, enabling organizations to deploy, scale, and manage containerized applications efficiently. CentOS Stream 10, known for its stability and cutting-edge features, provides an excellent foundation for running Kubernetes clusters. This comprehensive guide will walk you through the step-by-step process of installing Kubernetes on CentOS Stream 10, ensuring a secure and optimized setup.

Prerequisites and System Requirements

Before diving into the installation process, it’s essential to ensure that your system meets the necessary prerequisites and requirements to facilitate a smooth Kubernetes setup.

Hardware Requirements

  • RAM: Minimum of 2 GB per node, though 4 GB is recommended for better performance.
  • CPUs: At least 2 CPUs per node to handle the Kubernetes components efficiently.
  • Servers: A minimum of two servers is required—one master node and one worker node—to form a basic cluster configuration.

Network Requirements

  • Connectivity: Ensure full network connectivity between all nodes in the cluster to facilitate communication.
  • Ports: Open necessary ports for Kubernetes communication, including ports 6443 (Kubernetes API server), 2379-2380 (etcd server client API), and others as required.

User Permissions

  • Privileges: Root or sudo privileges are required on all nodes to perform the installation and configuration tasks.

Software Requirements

  • Operating System: CentOS Stream 10 must be installed on all nodes.
  • Updates: Ensure the system is up-to-date by running dnf update.

Step 1: Preparing the System

Proper system preparation is crucial for the successful installation of Kubernetes. This step involves updating system packages, disabling swap, enabling necessary kernel modules, and configuring sysctl parameters.

Update System Packages

Start by updating all existing packages to their latest versions:

sudo dnf update -y

Disable Swap

Kubernetes requires swap to be disabled for optimal performance and stability. Disable swap permanently by editing the /etc/fstab file and then turning it off:

sudo swapoff -a

Edit /etc/fstab and comment out any swap entries:

# /swap.img swap swap defaults 0 0

Enable Kernel Modules

Load the necessary kernel modules required by Kubernetes:

sudo modprobe br_netfilter
sudo modprobe overlay

Add these modules to the /etc/modules-load.d/kubernetes.conf file to ensure they’re loaded on boot:

echo -e "br_netfilter\noverlay" | sudo tee /etc/modules-load.d/kubernetes.conf

Set sysctl Parameters

Configure network settings to allow Kubernetes to function correctly:

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

Step 2: Installing Container Runtime (Containerd)

Kubernetes relies on a container runtime to manage container operations. Containerd is a popular choice due to its performance and simplicity.

Explanation of Containerd

Containerd is an industry-standard container runtime that manages the complete container lifecycle, from image transfer to execution and supervision.

Installation Steps

Add the Docker repository to your system to access containerd packages:

sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install Containerd using the DNF package manager:

sudo dnf install -y containerd.io

Create a default configuration file for Containerd:

sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml

Set the cgroup driver to systemd by editing the configuration file:

sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml

Restart and enable the Containerd service to start on boot:

sudo systemctl restart containerd
sudo systemctl enable containerd

Step 3: Adding Kubernetes Repository

To install Kubernetes components, add the official Kubernetes repository to your CentOS Stream 10 system.

Adding the Repository

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.32/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.32/rpm/repodata/repomd.xml.key
EOF

Updating Package Cache

Refresh the package cache to recognize the newly added Kubernetes repository:

sudo dnf makecache

Step 4: Installing Kubernetes Components

With the repository added, proceed to install the essential Kubernetes components: kubelet, kubeadm, and kubectl.

Installation

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

Enabling and Starting kubelet

Enable the kubelet service to start on boot and then start it:

sudo systemctl enable --now kubelet

Step 5: Initializing the Master Node

The master node orchestrates the Kubernetes cluster, managing workloads and ensuring the desired state of the applications.

Initializing the Cluster

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

This command initializes the Kubernetes control plane on the master node. The --pod-network-cidr flag specifies the IP range for pod networking.

Saving the Join Command

After initialization, kubeadm will provide a command to join worker nodes to the cluster. Save this command securely as it will be needed in Step 7.

Configuring kubectl for the Current User

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

This configuration allows you to interact with the Kubernetes cluster using kubectl.

Step 6: Setting Up Pod Network

A pod network is essential for Kubernetes pods to communicate with each other. This guide uses Calico as the pod network add-on.

Installing Calico

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

Verifying Pod Network Status

kubectl get pods --all-namespaces

Ensure that all Calico pods are running without issues.

Step 7: Joining Worker Nodes to the Cluster

With the master node set up and the pod network in place, it’s time to add worker nodes to the cluster.

Executing the Join Command

On each worker node, execute the join command obtained in Step 5:

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

Verifying Node Addition

kubectl get nodes

This command should display all nodes, including the newly added worker nodes, in a Ready state.

Step 8: Post-installation Configuration and Testing

After setting up the cluster, it’s prudent to perform post-installation configurations and tests to ensure everything operates as expected.

Deploying a Sample Application

Deploy an NGINX application to test the cluster’s functionality:

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

Accessing the Application

Retrieve the NodePort assigned to the NGINX service:

kubectl get services

Access the application using the master node’s IP address and the assigned NodePort.

Troubleshooting Common Issues

Despite following the steps meticulously, you might encounter issues during the installation process. Below are common problems and their solutions.

Swap Not Disabled

If Kubernetes detects that swap is enabled, it may prevent the kubelet from starting:

  • Verify swap status: free -h
  • Ensure swap is disabled permanently by checking /etc/fstab.

Firewall Issues

Incorrect firewall configurations can block essential Kubernetes ports:

  • Check open ports: sudo firewall-cmd --list-all
  • Open required ports using firewall-cmd --add-port=/tcp --permanent and reload the firewall.

Nodes Not Joining the Cluster

If worker nodes fail to join the cluster, ensure that the token used is still valid:

  • Generate a new token on the master node: kubeadm token create --print-join-command
  • Re-execute the join command on the worker nodes.

Congratulations! You have successfully installed Kubernetes. Thanks for using this tutorial for installing the Kubernetes on your CentOS Stream 10 system. For additional or useful information, we recommend you check the official Kubernetes website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button