Install Rancher on CentOS, 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 get started with the basic configuration.
- A CentOS system
- Access to a command line/terminal
- A user account with sudo or root privileges
- Multiple nodes you can use for your cluster
Install Rancher on CentOS
Step 1: Installing Docker
1. Update the system by running:
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 for the process to finish until you see the dependencies have installed.
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
How to Solve Docker Installation Error
You may get an ERROR saying the system cannot install docker-ce because it requires containerd.io.
To solve this problem, install containerd.io manually by running:
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
Step 2: Enabling the Docker Service
1. Start the Docker service and enable it to run on boot:
sudo systemctl start docker
sudo systemctl enable docker
2. Then, check the service status:
sudo systemctl status docker
The output should display the service is
Step 3: Installing Rancher
1. Launch the Rancher server inside a Docker container with the command:
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) and keeps it running (
--restart=always) listening to port
Note: Learn more about the
docker run command and the many different ways to run a container by checking out How To Use Docker Run Command With Examples.
2. Check whether the Rancher server is running by listing existing docker containers in running state:
You should see the Rancher container listed in the output.
3. Now you can open the Rancher user interface by navigating to the server IP number and port in the URL bar.
The basic Rancher configuration outlined in the steps below will help you create an admin user and launch a Kubernetes cluster.
Step 1: Setting Up Admin User
This first thing to do after launching Rancher is to set up the Admin user.
1. Click the ADMIN drop-down menu and select Access Control.
2. Select LOCAL configuration to move to the Local Authentication window.
3. Fill in the required information to set up an Admin user. Then, click Enable Local Auth to confirm.
Step 2: Provisioning a Host
1. Select the INFRASTRUCTURE drop-down menu and click HOSTS.
2. Start up the machine making 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 in the terminal window of the machine.
5. Close and wait for the new host to appear on the Host screen.
Step 3: Creating a Custom Kubernetes Cluster
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.
After reading this article, you should have successfully installed a Rancher server within a Docker container.
When setting up Kubernetes clusters, make sure to secure your workloads. To learn more about how to do so, refer to Kubernetes Security Best Practices.