Rocky Linux is one of the new distributions that emerged as an alternative to CentOS after CentOS's discontinuation in 2021. As a free and open-source project, Rocky Linux aims to provide a viable replacement for enterprise operating systems in application development.
The server-centric and performance-oriented nature of Rocky Linux makes it a good choice for running containerized workloads. However, managing app containers at scale requires a container orchestrator like Kubernetes.
This article will guide you through installing Kubernetes on Rocky Linux.

Prerequisites
- Two or more machines running Rocky Linux (Bare Metal Cloud offers server instances that are deployed automatically with Rocky Linux).
- 2 GB of RAM and 2 CPU cores or more on each machine.
- Sudo or root access for each system.
- Ansible installed (for the 2nd method).
Install Kubernetes on Rocky Linux (Manual Method)
Manual installation of Kubernetes on Rocky Linux involves:
- Setting up a container runtime interface (CRI).
- Making adjustments to security and networking configuration.
- Installing the essential Kubernetes tools.
Note: Execute the installation steps on each node (physical or virtual machine) you plan to add to the cluster.
Step 1: Install containerd
containerd is a Docker-made CRI tool that creates, executes, and supervises containers. Follow the procedure below to set it up on your Rocky Linux system.
1. Add the official Docker repository to your system. Docker does not maintain a separate repository for Rocky Linux, but the CentOS repo is fully compatible.
The output confirms the success of the operation.
2. Refresh the local repository information.
3. Install the containerd.io
package.
4. Back up the default configuration file for containerd:
5. Create a new file with the default template:
6. Open the file in a text editor. This tutorial uses nano.
7. Find the SystemdCgroup
field and change its value to true
.
Save the file and exit.
8. Place the new file in the /etc/containerd
directory:
9. Enable the containerd service:
10. Open the Kubernetes modules configuration file:
11. Add the two modules required by the container runtime:
Save the file and exit.
12. Add the modules to the system using the modprobe command:
If the commands execute successfully, they return no output.
Step 2: Modify SELinux and Firewall Settings
For Kubernetes to work properly, cluster nodes need to communicate without interruptions. To ensure smooth networking, adjust SELinux permissions and open the necessary ports on each machine:
1. Change the SELinux mode to permissive with the setenforce
command:
2. Enter the following sed command to make changes to the SELinux configuration:
3. Confirm the changes by checking the SELinux status:
The value of the Current mode
field should be set to permissive
.
4. Add firewall exceptions to allow Kubernetes to communicate via dedicated ports. On the master node machine, execute the following commands:
The output confirms the success of the operation.
5. On worker nodes
, open the following ports:
6. Reload the firewall configuration to enforce the changes.
Step 3: Configure Networking
Kubernetes requires filtering and port forwarding enabled for packets going through a network bridge. Perform the network configuration in the k8s.conf
file:
1. Open the file in a text editor:
2. Ensure the file contains the following lines:
Save the file and exit.
Note: Read our tutorial to find out how can you save a file in Vim and exit.
3. Apply the changes with the sysctl command:
The system processes the k8s.conf
file for changes.
Step 4: Disable Swap
For performance reasons and the maximum utilization of each node's resources, Kubernetes requires virtual memory to be disabled on each node.
1. Disable swap with the swapoff
command.
2. Make the changes persist across reboots by typing:
Step 5: Install Kubernetes Tools
The following are the three main packages in a Kubernetes installation:
- kubeadm helps initialize a Kubernetes cluster.
- kubelet runs containers on each node.
- kubectl is the command-line utility for controlling the cluster and its components.
Install the packages by following the procedure explained below:
1. Create a repository file for Kubernetes:
2. Copy the repository specification below and paste it into the file.
Save the file and exit.
3. Refresh the local repository cache.
When prompted, type Y
and press Enter.
4. Install the packages with the following command.
The system is now ready to deploy a Kubernetes cluster.
Install Kubernetes on Rocky Linux Using Ansible
Ansible is an IaC tool that facilitates infrastructure deployment automation. It uses human-readable instruction files called playbooks to simplify and speed up repetitive deployments.
The following sections provide instructions for installing Kubernetes using Ansible.
Step 1: Connect Hosts
To enable communication between the Ansible host and the Kubernetes nodes, connect the machines via SSH.
1. Generate an SSH key:
When prompted, type the filename for the new key and press Enter. Next, press Enter two more times to create an empty passphrase.
2. Copy the credentials to each machine:
For example, to copy the id_rsa
key to the machine with the IP address 10.240.12.82
, type:
3. Create and go to the kube directory.
4. Create a file titled hosts using a text editor:
5. Paste the information about the nodes into the file. Split the info into two sections, masters and workers:
Save the file and exit.
6. Test the connectivity between the nodes and the Ansible host by typing:
The output confirms that Ansible has pinged the machines successfully.
Step 2: Create Users
The first playbook that needs to be applied creates a user called kube on each machine. This user receives an authorized SSH key and permissions that allow it to run sudo
commands without providing a password.
1. Create a playbook YML file in a text editor:
2. Copy and paste the code below into the file.
Save the file and exit. The playbook now contains a set of tasks that Ansible will execute on the relevant connected machines.
3. Run the playbook by typing:
The output shows the progress for each task.
Step 3: Install Kubernetes
After the necessary setup, create the playbook instructing Ansible to install Kubernetes tools on each node.
1. Create a YAML file in a text editor.
2. Copy and paste the following code into the file.
Note: Do not forget to replace the [current-user]
value in the remote_user
field with the current username on your Ansible host.
Save the file and exit.
3. Execute the playbook by entering the following:
When Ansible finishes all the operations, it displays a Play Recap.
Kubernetes has been successfully installed on all the nodes.
Conclusion
After completing this tutorial, you should know how to install Kubernetes on Rocky Linux and prepare for cluster deployment. The tutorial covered two methods for installation - manual and via Ansible-based.
If you are still looking for the best replacement for CentOS, read our comparison article Rocky Linux vs. AlmaLinux, to see how the two major competitors stack up against each other.