In this guide, we shall be installing Rancher across Ubuntu 18.04 LTS servers. Rancher is a Docker management utility. It is built on top Docker itself, meaning that there’s a docker container inside which Rancher runs. But there’s more to it than just that. Rancher can manage your containers not on just one node but across multiple nodes thanks to its excellent support for Kubernetes.
To follow along you will be required to have the following:
- Two Ubuntu 16.04 servers with a public IP addresses one to act as Rancher admin server and the second one will be a node or a host where our application with be running.
- Root privileges to both the servers.
- A Free or Enterprise GitHub Account
Here’s the list of our VPS servers with their names and public IP. Yours will differ from these and to follow along just substitute the IP addresses as they appear.
The Rancher server would run on
rancher-admin node and the rancher-node-01 will be controlled via this admin. Of course, for large-scale applications, there will be more than one node as a part of your infrastructure.
Step 1: Installing Docker and Rancher
Since we are using Ubuntu 16.04 LTS for our server OS, installing docker is as simple as running:
$ sudo apt install docker.io
You must install docker on all the nodes not just on the Rancher admin server.
Once docker is installed everywhere, it is time to install Rancher on your chosen admin server. On your chosen server, and on that server only, pull the rancher/server image by running the following command:
$ docker run -d --name rancher-server -p 8080:8080 rancher/server
This creates the Rancher container. We can now visit the public IP address at port 8080 to use the Rancher WebUI.
In our case, this address was
http://22.214.171.124:8080 your IP address might differ and you can also use a different port number if you like (just replace the first 8080 to the desired value.)
Step 2: Securing the Installation
The next immediate step is to secure your installation. On visiting the IP address of your Rancher server (on the specified port number as described in step 1) you will notice a warning sign beside Admin menu.
Hover your cursor over on Admin and go to Access Control option that appears under it. Once you are in Access Control menu you will be shown several options to configure your access control. These include Active Directory, LDAP, Local passwords but we will be using GitHub as it presents a much more succinct and practical use case.
If you select GitHub, then Rancher will guide you through the setting up access control via GitHub’s OAuth service. You can follow those steps or feel free to just click here and log in to GitHub account if you haven’t already, and click on Register a new application.
Fill out the application details as show in Rancher menu onto the GitHub application registration form, as shown below
Once your application is registered it will provide you with a Client ID and Client Secret. Copy them to the respective fields in your Rancher Access Control Set up and Save. After that, a new pop-up window will ask you whether or not is it okay to grant Rancher a read access to your GitHub account. Go ahead and authorize the app and our Rancher setup is now secure. Now you can log in to your Rancher UI via GitHub.
Step 3: Adding a Host
As mentioned before, Rancher is built to handle distributed systems like Kubernetes. This means a lot of nodes (virtual machines or physical servers) become the cattle and Rancher handles them. These nodes will have Docker installed on them and containers would be replicated and load balanced across multiple nodes to offer better scalability and availability.
We will be adding just one node on which we will be running our containers. Rancher comes with multiple options for automating this process for cloud providers like AWS, DigitalOcean, Azure and Packet we will be going to use the custom option as it has the most generic approach which would work on any of these platforms as well.
Go to Infrastructure → Hosts → Add Host and Select Custom as your choice.
Since we have already created a second VPS, which will be our cattle node with Docker installed on it, we can enter this node’s public IP in the Rancher Add Host form up as shown below:
That will generate a command with credentials that you are supposed to run on your worker node to connect it to your Rancher server. The command will fetch a few docker images to run to make administration easier.
Once that is done, you have your new host added and listed in your Rancher UI.
Step 4: Running containers
Containers are our fundamental unit of deployment here. Rancher treats docker containers as first-class citizens. Even its own components are segregated into different containerized apps.
If you go to Infrastructure → Containers → Add Container, you can see that it has a pretty UI to configure your container according to your application or microservice’s need. For example, if I need a web server for my Front-End UI I can do so by using Ubuntu 16.04’s docker image and mapping port 80 on the host to port 80 on the container and later installing your front-end app in it.
Furthermore, if you scroll down you will get more options on Networking, Storage, Security, etc. We encourage you to tweak these settings and to experiment with them. We will, however, do just one thing, ensure that interactive terminal is available so we can start a user session inside the container.
And now click create and you are done with the deployment.
This is where the real exploration would begin. Rancher will monitor resource utilization for you, and present it to you in a visually intuitive way.
You can click on the 3 vertical ellipses (shown by the arrow) you get the option to start, stop or delete the container along with a really useful option of executing the shell. Yes, you can open up a terminal straight into the container from your Web UI!
It is really hard to use Rancher and not get addicted to it. If you are an aspiring DevOps or if you are a small team trying to handle a massive application, Rancher offers an easy to use and intuitive UI to better understand and manage your infrastructure.