0% found this document useful (0 votes)
45 views6 pages

K8s Installation On Rocky Linux

Uploaded by

johariqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views6 pages

K8s Installation On Rocky Linux

Uploaded by

johariqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

How to Install Kubernetes on Rocky Linux

9 | AlmaLinux 9

Table of Contents

● Minimum System Requirement for Kubernetes


● Step 1 Set Hostname and Update Hosts file (Not needed for our case)
● Step 2 Disable Swap Space on Each Node
● Step 3 Adjust SELinux and Firewall Rules for Kubernetes
● Step 4 Add Kernel Modules and Parameters
● Step 5 Install Conatinerd Runtime (Partially needed for us)
● Step 6 Install Kubernetes tools
● Step 7 Install Kubernetes Cluster on Rocky Linux 9 / Alma Linux 9
● Step 8 Install Calico Network Addon
● Step 9 Test Kubernetes Cluster Installation

Step 1: Set Hostname and Update Hosts file


Not needed for us as our DNS is already configured with the appropriate entries.

Step 2: Disable Swap Space on Each Node


For kubelet to work smoothly, we must disable swap space on all the nodes. Run beneath
command,

$ sudo swapoff -a
$ sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Step 3: Adjust SELinux and Firewall Rules for Kubernetes
Set SELinux mode as permissive on all the nodes using following commands,

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

On the master node, allow following ports in the firewall.

$ sudo firewall-cmd --permanent


--add-port={6443,2379,2380,10250,10251,10252,10257,10259,179}/tcp
$ sudo firewall-cmd --permanent --add-port=4789/udp
$ sudo firewall-cmd --reload

On the Worker Nodes, allow beneath ports in the firewall,

$ sudo firewall-cmd --permanent --add-port={179,10250,30000-32767}/tcp


$ sudo firewall-cmd --permanent --add-port=4789/udp
$ sudo firewall-cmd --reload

Step 4: Add Kernel Modules and Parameters


For kuberetes cluster, we must add the overlay and br_netfilter kernel modules on all the nodes.

Create a file and add following content to it,

$ sudo tee /etc/modules-load.d/containerd.conf <<EOF


overlay
br_netfilter
EOF

In order to load above modules, run

$ sudo modprobe overlay


$ sudo modprobe br_netfilter

Next, add the following kernel parameters, create a file and with following content,

$ sudo vi /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward =1
net.bridge.bridge-nf-call-ip6tables = 1

Save & close the file.

Now add these parameters by running below command

$ sudo sysctl --system

Step 5: Install Conatinerd Runtime

(Containerd was already installed along with Docker in our case). However, some configuration
would be required here as below:

Configure containerd so that it will use systemdcgroup, execute the following commands on
each node.

$ containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1


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

Restart and enable containerd service using beneath commands,

$ sudo systemctl restart containerd


$ sudo systemctl enable containerd

Verify conatinerd service status, run

$ sudo systemctl status containerd

Step 6: Install Kubernetes tools


Kubernetes tools like Kubeadm, kubectl and kubelet are not available in the default package
repositories of Rocky Linux 9 or AlmaLinux 9. So, to install these tools, add the following
repository on all the nodes.

$ cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo


[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF

Next, install Kubernetes tools by running following dnf command,

$ sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

After installing Kubernetes tools, start the kubelet service on each node.

$ sudo systemctl enable --now kubelet

Step 7: Install Kubernetes Cluster on Rocky Linux 9 /


Alma Linux 9

(Only for Master Node)


Now, we are all set to install Kubernetes cluster. Run beneath Kubeadm command to initialize
the Kubernetes cluster from the master node.

$ sudo kubeadm init --control-plane-endpoint=<master_node_host_name>

To start interacting with Kubernetes cluster, run the following commands on the master node.

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

(Only for Worker Node)

Next, join the worker nodes to the cluster, run following Kubeadm command from the worker
nodes.
kubeadm join dwl-lab-021.ncp.edu.pk:6443 --token v1h7k9.1i7tpph7toorw3ke \
--discovery-token-ca-cert-hash
sha256:f75461772dce97c06118e03bb4d76a12c44a4ef0c694edbb0213291ad97d8faf

Now, head back to master node and run kubectl command to verify the nodes status.

$ kubectl get nodes

Step 8: Install Calico Network Addon


Calico network addon is required on Kubernetes cluster to enable communication between
pods, to make DNS service function with the cluster and to make the nodes status as Ready.

In order to install calico CNI (Container Network Interface) addon, run following kubectl
commands from the master node only.

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

Verify calico pods status,

$ kubectl get pods -n kube-system

Next, verify the nodes status, this time nodes status should be in Ready State.

$ kubectl get nodes

Step 9: Test Kubernetes Cluster Installation

To test Kubernetes cluster installation, let’s try to deploy nginx based application using
deployment. Run following kubectl commands,

$ kubectl create deployment web-app01 --image nginx --replicas 2


$ kubectl expose deployment web-app01 --type NodePort --port 80
$ kubectl get deployment web-app01
$ kubectl get pods
$ kubectl get svc web-app01

Try to access the application (via web browser) using nodeport such as “31121”, run following
curl command,

$ curl <worker_node_name>:31121

You might also like