How to Install Rancher on CentOS and Rocky Linux

December 25, 2024

Introduction

Rancher is a container management platform used by virtualization vendors with Kubernetes in their standard infrastructure. The software simplifies deploying, running, and managing Kubernetes at scale.

In this tutorial, you will learn how to install Rancher on CentOS and Rocky Linux and get started with the basic configuration.

How to install Rancher on CentOS and Rocky Linux - a tutorial.

Prerequisites

Install Rancher on CentOS and Rocky Linux

Rancher is not available in the default CentOS or Rocky Linux repositories. Therefore, to install Rancher, we will use Docker as a container orchestration platform and deploy Rancher as a container. Follow the steps in the sections below.

Step 1: Installing Docker

Ensure Docker is installed on your system since Rancher runs as a container.

1. Update the system package index with:

sudo yum check-update

2. Uninstall old Docker versions with:

sudo yum remove docker docker-engine docker.io

3. Download the dependencies:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Wait until the dependencies are installed.

Download Docker dependencies on Rocky Linux.

4. Add the official Docker repository:

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

5. Now install Docker by running:

sudo yum install docker-ce -y
Install Docker on Rocky Linux.

Wait for the process to complete.

How to Solve Docker Installation Error on CentOS & Rocky Linux

You may get an ERROR saying the system cannot install docker-ce because it requires containerd.io.

Output showing Docker cannot install on CentOS.

To solve this problem, install containerd.io manually with the command below:

yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

Now, repeat the Docker installation command:

sudo yum install docker-ce -y

Step 2: Enable the Docker Service

After the installation, make sure that the Docker service is running.

1. Start the Docker service and enable it to run on boot:

sudo systemctl start docker
sudo systemctl enable docker

2. Check the service status with:

sudo systemctl status docker

The output should display the service is active (running).

Checking the Docker service status on Rocky Linux.

Press q to return to the terminal.

Step 3: Install Rancher

Now that Docker is up and running, you can deploy Rancher as a container.

1. Launch the Rancher server inside a Docker container with the docker run command:

sudo docker run -d --restart=always -p 8080:8080 rancher/server:stable

Docker pulls the latest stable Rancher image and launches the container. The command above runs the container in detached mode (-d), keeps it running, (--restart=always) and maps port 8080 on your host machine to port 8080 inside the container.

2. List existing docker containers in running state to check whether the Rancher server is running:

sudo docker ps

You should see the Rancher container listed in the output.

Verify that the Rancher container is running in Docker.

3. Navigate to the server IP number and port in the URL bar to open the Rancher user interface. Since we are working locally, our IP is localhost (127.0.0.1), and the port is 8080:

Launch Rancher interface on CentOS.

Configure Rancher on CentOS and Rocky Linux

The basic Rancher configuration outlined in the steps below will help you create an admin user and launch a Kubernetes cluster.

Step 1: Set Up Admin User

The first thing to do after you launch Rancher is to set up the Admin user. To do so:

1. Click the ADMIN drop-down menu and select Access Control.

Configure Rancher on CentOS.

2. Select LOCAL configuration to move to the Local Authentication window.

Select LOCAL configuration from the access control menu.

3. Fill in the required information to set up an Admin user. Then, click Enable Local Auth to confirm.

Set up an Admin User for Rancher.

Step 2: Provision a Host

1. Select the INFRASTRUCTURE drop-down menu and click HOSTS.

2. Start up the machine and make sure it has a supported version of Docker and allows traffic to and from hosts on ports 500 and 4500.

3. Add the IP address of the host.

4. Copy and paste the generated command into the terminal window.

5. Close and wait for the new host to appear on the Host screen.

Step 3: Create Custom Kubernetes Cluster

A custom Kubernetes cluster is a user-defined Kubernetes environment where nodes are manually provisioned and configured. It is tailored to specific requirements instead of relying on a managed service or predefined setup.

1. Open the Clusters page and select Add Cluster.

2. Choose Custom, provide a Cluster Name, and click Next.

3. Choose what roles you want the nodes to have (etcd, Control Plane, and/or Worker) from the Node Options.

4. Copy and paste the generated command on each worker node machine. Each machine within the cluster must have a supported version of Docker installed. Finally, wait for the cluster to start up.

Note: Refer to our in-depth guide How to Set Up a Kubernetes Cluster with Rancher for more details on managing clusters with Rancher.

Conclusion

After reading this article, you should have successfully installed a Rancher server within a Docker container.

When you set up Kubernetes clusters, make sure to secure your workloads. To learn more about how to do so, refer to Kubernetes Security Best Practices.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
How to Install Rancher on Ubuntu
September 2, 2020

Install Rancher on your Ubuntu server and get started using this container management platform that helps...
Read more
How to Restart Kubernetes Pods
November 27, 2023

Kubernetes is one of the premier systems for managing containerized applications. But it isn't always able to...
Read more
How to Update Docker Image and Container to the Latest Version
July 11, 2024

To avoid running containers with outdated Docker images, update the image and run the container with the...
Read more
How to Install Jenkins on Kubernetes Cluster
December 25, 2024

Use a provided set of YAML files to deploy scalable Jenkins on Kubernetes in 4 easy steps. Use Jenkins to...
Read more