×
Community Blog How to Install Rancher on an Alibaba Cloud ECS instance

How to Install Rancher on an Alibaba Cloud ECS instance

In this blog, you will learn how to install Rancher on an Alibaba Cloud ECS instance that is installed with Ubuntu 16.04.

By Sajid Qureshi, Alibaba Cloud Community Blog author.

Rancher is an open-source Docker container management platform. It includes a Kubernetes distribution as well as the option to choose from Docker Swarm and Apache Mesos. You can run and manage Docker and Kubernetes containers very easily using Rancher. Rancher provides a huge library of applications which can be installed within a few clicks. It also includes modular infrastructure services including networking, load balancing, service discovery, monitoring and recovery.

Prerequisites

You must have an Alibaba Cloud Elastic Compute Service (ECS) instance activated and have verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don't know about how to set up your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.

Procedure

Follow the steps outlined below to learn how to install Rancher on an Alibaba Cloud ECS instance.

Installing Docker

Before you install and run Rancher, you will need to install Docker first as it is required for Rancher. First of all, remove any old docker files using the following command.

sudo apt-get remove docker docker-engine docker.io

Next, update all the available packages. Run the sudo apt-get update command and it will do the job for you. Then, install packages to allow apt to use a repository over HTTPS using the following command:

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

Add Docker's official GPG key using the following command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Now verify that you have the key 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 by searching for last 8 digits of the key's fingerprint. You can use the following command:

sudo apt-key fingerprint 0EBFCD88

You should see an output something similar to this:

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

Now setup the stable repository using the following command:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Next, update the package list again using the sudo apt-get update command, and list all the available versions of Docker in your repository using the following command.

apt-cache madison docker-ce

The output should be like this:

docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.06.2~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.06.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.06.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.03.2~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

Append the version-string, which is the second column, of the latest stable version after the = in the following command to install the latest version of Docker CE. Now install a specific version of Docker of your choice using the following command.

sudo apt-get install docker-ce=17.09.1~ce-0~ubuntu

You can also install Docker without appending any version-string, but we recommend you to install a specific version of Docker for the production environment. Now verify that the Docker is installed correctly using the following command:

sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits. You should see the message similar to the following output.

Hello from Docker!

This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

Install Rancher

We have installed all the dependencies required and now we are ready to install and run Rancher. Run the following Docker command and it will do the job for you.

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

It takes less than a minute for the Rancher server to start up. Then open up your favorite web browser and visit port 8080 on your server http://YourServerIP:8080. If nothing goes wrong, then you will see a Rancher user interface and it will guide you through adding your first cluster.

1

Configure Rancher Access Control

After the Rancher installed, you will need to configure access control. You can manage your users who have the permission to your Rancher server by configuring Rancher access control.

Move the cursor to the ADMIN menu on top of the web page and click on the Access Control. We want to use the local authentication method so, click on the LOCAL and then type your username and password. Finally, click on the Enable Local Auth button. You will be redirected to the Rancher dashboard with local authentication enabled.

Add a New Host

Hosts are the most basic unit of resource within Rancher and are represented as any Linux server, virtual or physical. In order to add a new host to Rancher, you will need to create a new Alibaba Cloud ECS instance. Here we are using a new Alibaba Cloud ECS instance with Ubuntu operating system and having at least 2 GB RAM. First of all, set a new hostname to distinguish between these two servers. Run the following command and set a hostname of your choice.

sudo hostnamectl set-hostname host01

Now connect to the host server using ssh like this:

ssh sajid@IPAddress of host01  

Next, install the latest Docker version using this script.

curl -fsSL https://get.docker.com -o get-docker.sh

Run this script using the sh get-docker.sh command, and it will do the job for you. After the Docker is installed, you will need to start the docker services and enable it to launch at the boot time using the following commands.

systemctl start docker
systemctl enable docker

Next, you will have to add rancher host01 to rancher server and to do so, open the Rancher dashboard and move your cursor to the INFRASTRUCTURE menu and click on Hosts. On the next screen, click on the Add Host button and now you'll be asked for the Host Registration URL, here we will use default and click on the Save button.

On the next interface, select the host type. Rancher supports many host types such as Amazon EC2, Azure, DigitalOcean, and Exoscale host. For now, choose the custom host type, and enter the IP Address of rancher host01 server and copy the Docker command in the box.

Now go to rancher host01 terminal shell and paste the docker command like this:

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 above command will download and create new container Rancher Agent on the rancher-host01 server. Finally, go back to Rancher dashboard host add page and click on the Close button.

Conclusion

In this tutorial, you learned to install Docker and Rancher on your Alibaba Cloud ECS instance installed with Ubuntu 16.04. You also configured Docker and Rancher on Alibaba Cloud ECS instance. Plus, you added a rancher host similarly. With it, you can deploy more hosts and you are ready to deploy other container and applications.

0 0 0
Share on

Alibaba Clouder

1,500 posts | 242 followers

You may also like

Comments

Alibaba Clouder

1,500 posts | 242 followers

Related Products