Step-by-step guide to install Kubernetes (K8s) on Red Hat Enterprise Linux (RHEL) 9.5

 Here’s a step-by-step guide to install Kubernetes (K8s) on Red Hat Enterprise Linux (RHEL) 9.5, using kubeadm, the official Kubernetes tool.


✅ Prerequisites

  1. Root / sudo access

  2. Swap disabled

  3. Docker or containerd installed

  4. Firewall open for Kubernetes ports

  5. Unique hostname, static IP, and DNS resolution for each node


🔧 Step 1: Disable Swap

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

🔧 Step 2: Set Hostname

sudo hostnamectl set-hostname <node-name>

Example:

sudo hostnamectl set-hostname master-node

🔧 Step 3: Add Kubernetes Repository

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

You can change v1.30 to a specific version if required.


🔧 Step 4: Install kubeadm, kubelet, kubectl

sudo dnf install -y kubelet kubeadm kubectl

Lock their version to avoid accidental upgrades:

sudo dnf mark install kubelet kubeadm kubectl

🔧 Step 5: Enable and Start kubelet

sudo systemctl enable --now kubelet

🔧 Step 6: Install Container Runtime (Containerd)

Kubernetes no longer supports Docker directly; use containerd.

sudo dnf install -y containerd

Generate default config:

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

Enable Systemd cgroup driver:
Edit /etc/containerd/config.toml and set:

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] SystemdCgroup = true

Then restart containerd:

sudo systemctl restart containerd sudo systemctl enable containerd

🔧 Step 7: Enable Kernel Modules and Set Sysctl

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf overlay br_netfilter EOF sudo modprobe overlay sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 EOF sudo sysctl --system

🟩 Step 8: Initialize Kubernetes Cluster (on Master Node)

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

After success, copy the admin config:

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

🟩 Step 9: Install Pod Network Add-on (like Calico or Flannel)

Example with Calico:

kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/calico.yaml

🟨 Step 10: Join Worker Nodes (optional)

On master, you'll get a kubeadm join command—copy that and run it on each worker node.


✅ Verify

kubectl get nodes

You should see your master node in Ready state.


⚠️ Notes

  • Make sure firewall ports (6443, 10250, etc.) are open.

  • If using RHEL with SELinux, ensure it's not interfering.

  • Run kubeadm reset if you need to clean and reinstall.

No comments:

Post a Comment