Cyberithub

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step]

Advertisements

In this article, I will take you through the steps to install Rancher on Ubuntu 20.04 LTS. If you have Kubernetes cluster running on multiple environments and you are currently looking to unify them all in one place so that it will be easy to manage all the workloads then Rancher is the best solution you can think to use here. Rancher is most suitable to be deployed in an Organization where you have Kubernetes clusters running on premises, on cloud and on edge. It unifies all these clusters to ensure consistent operations, workload management and enterprise-grade security.

It is a complete software stack which can be used by any teams who are currently working or looking to work with containers. It is also very easy to install and setup in a Linux based system. Here we are going to install rancher on Ubuntu 20.04 LTS Linux distribution.

Some Important Features

  • It implements a portable layer of infrastructure services designed specifically to power containerized applications.
  • It provide infrastructure services including networking, storage, load balancer, DNS, and security.
  • It has a distribution of all popular container orchestration and scheduling frameworks.
  • It can deploy an entire multi-container clustered application from the application catalog with just a click of a button.
  • It supports flexible user authentication plugins.
  • It supports Role Based Access Control (RBAC) at the level of environments.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step]

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step]

Also Read: How to Create a Large File in Linux [4 Simple & Easy Methods]

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server

b) You should have sudo or root access to run privileged commands.

c) Yo should have curl utility installed in your Server.

d) You should have one Rancher server and atleast one host to connect. In our case, it is:-

  • 192.168.29.110: Rancher Server
  • 192.168.29.114: Connecting Host

 

Step 2: Install docker

You can download and install docker through multiple methods. Here we are using the most simpler one through below shell script. This is taken from GitHub. You can also visit and get the latest one.

root@localhost:~# curl https://releases.rancher.com/install-docker/20.10.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 17683 100 17683 0 0 18419 0 --:--:-- --:--:-- --:--:-- 18400
# Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sh -c echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
INFO: Searching repository for VERSION '20.10.7'
INFO: apt-cache madison 'docker-ce' | grep '20.10.7.*-0~ubuntu' | head -1 | awk '{$1=$1};1' | cut -d' ' -f 3
+ [ -n 5:20.10.7~3-0~ubuntu-focal ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce-cli=5:20.10.7~3-0~ubuntu-focal >/dev/null
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce=5:20.10.7~3-0~ubuntu-focal >/dev/null
+ [ -n 1 ]
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce-rootless-extras=5:20.10.7~3-0~ubuntu-focal >/dev/null
+ start_docker

 

Step 3: Check Docker Version

After successful docker installation, you can test it by running docker --version command as shown below.

root@localhost:~# docker --version
Docker version 20.10.7, build f0df350

 

Step 4: Check Docker Service

You need to check and verify the running status of docker using systemctl status docker command. It should be active and in running status as you can see below. But in case, if it is not running then you can try to start it by using systemctl start docker or even restart by using systemctl restart docker command.

root@localhost:~# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-12-14 20:08:59 IST; 3min 31s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 8359 (dockerd)
Tasks: 8
Memory: 40.1M
CGroup: /system.slice/docker.service
└─8359 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

 

Step 5: Install Rancher

Now that you have docker installed in your System, you can run rancher container by pulling stable rancher server image from library using below docker command.

root@localhost:~# docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable
Unable to find image 'rancher/server:stable' locally
stable: Pulling from rancher/server
bae382666908: Pull complete
29ede3c02ff2: Pull complete
da4e69f33106: Pull complete
8d43e5f5d27f: Pull complete
b0de1abb17d6: Pull complete
422f47db4517: Pull complete
79d37de643ce: Pull complete
69d13e08a4fe: Pull complete
2ddfd3c6a2b7: Pull complete

............................................................................

b247b6963d41a57f739d4d4adcfdf5302f3c54f1f3943f72bb88897c77c9159c

 

Step 6: Check Running Container

Once the container is created and running, you can verify the running status by using docker ps -a command as shown below.

root@localhost:~# docker ps -a
CONTAINER ID IMAGE                 COMMAND                CREATED        STATUS        PORTS NAMES
b247b6963d41 rancher/server:stable "/usr/bin/entry /usr…" 16 seconds ago Up 12 seconds 3306/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp relaxed_gates

 

Step 7: Access Rancher

You can go to your favorite web browser and open http://<your_server_ip_address>:8080/ URL as shown below. You should be able to access default rancher page as you can see below.

NOTE:

Please make sure Port 8080 is free and allowed through firewall in case you are running one in your System.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 2

 

Step 8: Configure Rancher

Next step is to configure Rancher to allow or restricts access to accounts in local database. Here we are only going to allow access to our local admin user.

a) Open Access Control

You need to first open Access Control from Admin as shown below.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 3

b) Go to Local Authentication

Open Local authentication from Access Control as show below.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 4

c) Setup Local Authentication

You can setup an admin user by providing admin username and password. In our case, we are using cyberithub as username and then providing the password below.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 5

After clicking on Enable Local Auth, access control will be enabled and should show like below.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 6

 

Step 9: Provision Host

Next step is to provision hosts to connect Rancher API. Here we are going to connect an on-premise CentOS Host to Rancher.

a) Open Hosts

For that you need to first go to Hosts from Infrastructure as shown below.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 7

Then you need to Tap on Add Host button as shown below.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 8

b) Add Host

You will be asked to confirm the base URL that will be used by hosts to connect Rancher API. Once confirmed, click on Save.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 9

You need to select the appropriate option from below. Since in our case, host is on a local Virtual machine so we are selecting Custom option. You can select any of the below option depending on the location of your host.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 10

If you scroll below, you will be asked to provide the public IP which will be registered for the given host. If you don't provide any IP then rancher will auto-detect the IP to use. In our case, since host IP address is 192.168.29.114, we are providing this detail below. Then we need to copy the docker command given in Step 5, paste and run the same on the host which you are going to register with Rancher.

How to Install Rancher on Ubuntu 20.04 LTS [Step by Step] 11

Finally, we are running the command on our host as shown below. This will register our host to Rancher.

[root@localhost ~]# docker run -e CATTLE_AGENT_IP="192.168.29.114" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.11 http://192.168.29.110:8080/v1/scripts/DCA7D985CA43E57D32AB:1609372800000:GttZE9LkD7XVzkZl05DA7L0MDPY
Unable to find image 'rancher/agent:v1.2.11' locally
v1.2.11: Pulling from rancher/agent
b3e1c725a85f: Pull complete
6a710864a9fc: Pull complete
d0ac3b234321: Pull complete
87f567b5cf58: Pull complete
063e24b217c4: Pull complete
d0a3f58caef0: Pull complete
16914729cfd3: Pull complete
bbad862633b9: Pull complete
3cf9849d7f3c: Pull complete
Digest: sha256:0fba3fb10108f7821596dc5ad4bfa30e93426d034cd3471f6ccd3afb5f87a963
Status: Downloaded newer image for rancher/agent:v1.2.11

INFO: Running Agent Registration Process, CATTLE_URL=http://192.168.29.110:8080/v1
INFO: Attempting to connect to: http://192.168.29.110:8080/v1
INFO: http://192.168.29.110:8080/v1 is accessible
INFO: Configured Host Registration URL info: CATTLE_URL=http://192.168.29.110:8080/v1 ENV_URL=http://192.168.29.110:8080/v1
INFO: Inspecting host capabilities
INFO: Boot2Docker: false
INFO: Host writable: true
INFO: Token: xxxxxxxx
INFO: Running registration
INFO: Printing Environment
INFO: ENV: CATTLE_ACCESS_KEY=E739D1AFD249A01C5077
INFO: ENV: CATTLE_AGENT_IP=192.168.29.114
INFO: ENV: CATTLE_HOME=/var/lib/cattle
INFO: ENV: CATTLE_REGISTRATION_ACCESS_KEY=registrationToken
INFO: ENV: CATTLE_REGISTRATION_SECRET_KEY=xxxxxxx
INFO: ENV: CATTLE_SECRET_KEY=xxxxxxx
INFO: ENV: CATTLE_URL=http://192.168.29.110:8080/v1
INFO: ENV: DETECTED_CATTLE_AGENT_IP=192.168.29.114
INFO: ENV: RANCHER_AGENT_IMAGE=rancher/agent:v1.2.11
INFO: Launched Rancher Agent: c267e838846ebc4f8b63922e3492972660eb83e03d239f8e513e0754e4c62857

Leave a Comment