Rancher is an open source container management platform. It allows you to run and manage Docker and Kubernetes containers with ease. Rancher provides infrastructure services such as multi-host networking, load balancing, and volume snapshots.

In this tutorial, I will show you how to install and configure Rancher on Ubuntu 16.04 LTS. We will install Rancher on an Ubuntu server, enable local authentication, add the rancher host, and then try to run single container application from Rancher Dashboard.

Prerequisites

  • Ubuntu Server 16.04
    • hakase-labs – 192.168.33.10
    • rancher-host01 – 192.168.33.11
  • Root privileges

What we will do?

  1. Install Docker on Ubuntu 16.04
  2. Install Rancher Server
  3. Enable Local Authentication Rancher Server
  4. Add New Host
  5. Deploy New Container

Step 1 – Install Docker on Ubuntu 16.04

Rancher can be installed as a set of Docker Containers – one container as a management server and another as an agent. And we need the Docker installed on all our rancher hosts.

Update your Ubuntu repository and upgrade all packages.

sudo apt update

sudo apt upgrade

Now install docker using the apt command below.

sudo apt install -y docker.io

After the installation is complete, start the docker service and enable it to run everytime at system boot.

systemctl start docker

systemctl enable docker

The Docker is now installed and running on our rancher host – check it using the command below.

systemctl status docker

docker --version

And you should get the result as shown below.

<img alt="Start docker and check docker version" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/1.png66052f87f15c7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="326" loading="lazy" src="data:image/svg xml,” width=”500″>

Step 2 – Install Rancher Server

To run and install Rancher, we just need to run the Rancher container on our host. In this step, we will install Rancher server single container on our ‘host01’ server.

Before installing Rancher server on the ‘hakase-labs’ server, we will create and define a new directory as a Rancher database volume.

Run the following commands.

HOST_VOLUME=$HOME/rancher-data/mysql

mkdir -p $HOST_VOLUME

Now install Rancher server using the docker command below.

sudo docker run -d 

-v $HOST_VOLUME:/var/lib/mysql

--restart=unless-stopped

-p 8080:8080

rancher/server

Wait for the Rancher server installation.

<img alt="Install rancher docker management software" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/2.png66052f8827018.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="210" loading="lazy" src="data:image/svg xml,” width=”500″>

When the installation is complete, Rancher server is accessible from the web browser.

Open your web browser and type the server IP address with port 8080.

http://192.168.33.10:8080/

And you will get the Rancher first page installation as below.

<img alt="Add first stack to Rancher" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/3.png66052f8841e3c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="290" loading="lazy" src="data:image/svg xml,” width=”500″>

Step 3 – Configure Rancher Access Control

After the Rancher installation, we need to configure the Rancher Access Control. The Access Control allows you to manage users who have the access permissions to your Rancher server.

Rancher supports many access control providers, including Active Directory, Azure AD, Github, OpenLDAP, SAML, and Local Authentication.

For this guide, we will enable the local authentication for our Rancher server installation.

Open your web browser and type the server IP address with port 8080.

http://192.168.33.10:8080/

Move the cursor to the ‘ADMIN’ menu and click the ‘Access Control’.

<img alt="Manage access control" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/4.png66052f88882bf.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="194" loading="lazy" src="data:image/svg xml,” width=”500″>

Now we want to use the ‘Local Authentication’ method. Click the ‘LOCAL’ on the page, then type your username and password.

<img alt="Use local authentication" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/5.png66052f88c2b65.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="282" loading="lazy" src="data:image/svg xml,” width=”500″>

And click ‘Enable Local Auth’ button.

And you will be redirected to the Rancher Dashboard with Local Authentication enabled.

<img alt="Enable local authentication in Rancher" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/6.png66052f88e77e9.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="207" loading="lazy" src="data:image/svg xml,” width=”500″>

Step 4 – Add New Host

Hosts are the most basic unit of resource within Rancher and represented as any Linux server (a virtual or physical server with Docker installed on it).

In this step, we will add new host ‘rancher-host01’ with Ubuntu as an operating system and 2GB RAM.

Connect to the ‘rancher-host01’ server using the ssh.

ssh rot@rancher-host01

Install latest Docker version to the server using the apt command.

sudo apt install docker.io

After the installation is complete, start the docker service and enable it to launch everytime at system boot.

systemctl start docker

systemctl enable docker

The Docker has been installed on the ‘rancher-host01’ server.

<img alt="Check docker version on host and node" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/7.png66052f8936a6a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="384" loading="lazy" src="data:image/svg xml,” width=”500″>

Next, we will add the rancher-host01 to the Rancher Server.

Open the Rancher Dashboard, move your cursor to the ‘INFRASTRUCTURE’ menu and click ‘Hosts’.

<img alt="Open Rancher dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/8.png66052f8977ba3.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="190" loading="lazy" src="data:image/svg xml,” width=”500″>

Now click ‘Add Host’ button.

<img alt="Add host to Rancher" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/9.png66052f89b4aef.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="163" loading="lazy" src="data:image/svg xml,” width=”500″>

For the Host Registration URL, we will use default as below.

<img alt="Host registration URL" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/10.png66052f89e6c3d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="242" loading="lazy" src="data:image/svg xml,” width=”500″>

Click the ‘Save’ button.

Now select the Host type. Rancher support for many Host type including Amazon EC2, Azure, DigitalOcean, and Rackspace Hosts.

Choose the ‘Custom’ host, type the ‘hots02’ IP address, and copy the docker command in the box.

<img alt="Add custom host" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/11.png66052f8a35dd6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="280" loading="lazy" src="data:image/svg xml,” width=”500″>

Now open the rancher-host01 terminal shell and paste the command as an example below.

sudo docker run -e CATTLE_AGENT_IP="192.168.33.11"  --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.9 http://192.168.33.10:8080/v1/scripts/C7871D15E9CE6FFA892F:1514678400000:T9qDygb2pHroTMBuqA9Jylol8tU

The command will download and create new container Rancher Agent on the rancher-host01 server.

And when it’s complete, you will get the result as below.

<img alt="Create new container agent" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/12.png66052f8a6215d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="296" loading="lazy" src="data:image/svg xml,” width=”500″>

Now back to the Rancher Dashboard Host Add page and click the ‘Close’ button.

And you will get the page as below.

<img alt="Host added" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/13.png66052f8a92532.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="171" loading="lazy" src="data:image/svg xml,” width=”500″>

rancher-host01 has been added to the Rancher server, and we’re now ready to run container managed by Rancher server.

Step 5 – Test Create New Container through Rancher Catalog

Rancher provides a catalog for applications. The application templates make it easy to deploy new applications.

Rancher provides two types of catalogs. The Library catalog, which contains templates from the Rancher certified catalog, and the Community catalog, which contains templates from the Rancher Community-catalog.

In this step, we will try to deploy a simple blog platform ‘Ghost’ as a container through the Rancher Catalog Community Templates.

On the Rancher Dashboard, move the cursor to the ‘CATALOG’ menu and click the Community Catalog.

<img alt="Application catalog" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/14.png66052f8ab7ec3.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="205" loading="lazy" src="data:image/svg xml,” width=”500″>

I the ‘Search’ box – type the application name that we want to install (‘Ghost’), then click the ‘View Details’ button.

<img alt="Search applications" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/14b.png66052f8ae6df2.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="219" loading="lazy" src="data:image/svg xml,” width=”500″>

Give the new Ghost container a name and description.

<img alt="Set container name" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/15.png66052f8b2ab8d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="288" loading="lazy" src="data:image/svg xml,” width=”500″>

Then click the ‘Launch’ button.

When it’s complete, you will get the result as below.

<img alt="Launch docker container" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/16.png66052f8b5cc76.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="161" loading="lazy" src="data:image/svg xml,” width=”500″>

The ‘Ghost’ container has been created and is now running on the Rancher agent server.

Now move your cursor to the ‘INFRASTRUCTURE’ menu and click the ‘Host’. And make sure you get the ‘ghost’ container is running on the ‘host2’ server.

<img alt="Infrastructure menu" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/17.png66052f8b99239.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="283" loading="lazy" src="data:image/svg xml,” width=”500″>

To verify the Ghost container installation, open your web browser and type the ‘rancher-host01’ IP address and you will get the ghost blog default homepage.

http://192.168.33.11/

<img alt="Ghost running in docker container deployed with Rancher" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/18.png66052f8bd0cdb.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="288" loading="lazy" src="data:image/svg xml,” width=”500″>

Rancher server and Rancher agent installation on Ubuntu 16.04 has been completed successfully.

Reference