Docker container management using Rancher

What is container management and why to use it?

A container management platform is a solution used to o create cloud-native, distributed applications and package legacy applications that were not originally designed for virtual environments. Container management software simplifies the process of adding or replacing containers when the need arises and facilitates the organization of large numbers of containers, automating much of the manual work. These platforms include orchestration, scheduling and storage functionality along with a Web-based UI to easily manage several aspects of container deployment. Some platforms are designed to function more effectively for small-scale testing and other, like the Rancher Container Management Platform, offer enterprise-grade networking and governance to securely manage containers in production across on-premises and cloud environments.

In this example we are going to deploy a total of two load balancers, three Rancher Container Management nodes in a High Availability deployment, three Docker hosts, and three MySQL hosts in a Galera cluster. All web request to Rancher will be will be sent to a load balancer IP and then distributed to each of the Rancher servers using a round robin policy. Similarly the Docker Container Hosts (DCH) will integrate into Rancher for management purposes and management communications are will be will be sent to a load balancer IP and then distributed to each of the Rancher servers using a round robin policy. Rancher will also communicate to the MySQL cluster using a load balancer in a similar fashion. The goal is to have multiple Rancher, Docker and MySQL nodes appear as one logical resource to protect again failure and ensure the Container Infrastructure will always be available.

Rancher prerequisites

Before we get started installing Rancher we need to take care of a few prerequisites for Rancher version 1.6.8. If the following items and conditions are not met the Rancher deployment may not be successful.

Step 1: The below MySQL queries will confirm which version of MySQL you are running and the table format. If your MySQL deployment does not meet the mentioned requirements below you can follow the guide I've written to Install MySQL Galera Cluster on Centos 7.

Step 2: Prepare two HAProxy load balancers, one to load balance MySQL connections from Rancher and one to load balance connections to Rancher. If you need help preparing load balancers I would suggest using HAProxy as it is easy to configure and manage. Here you can find guides for HTTP Load Balancing using HAProxy and MySQL Load Balancing using HAProxy

NOTE: The HAProxy load balancer represents a single point of failure. The HAProxy deployed as part of this guide is used for simplicity. It is recommended to use a clustered load balancer for both MySQL and HTTP connections such as a F5 or NGINX Plus Clustered load balancer.

Steps to configure Rancher

Step 4: Login to your MySQL cluster and create an empty database named cattle. Do not create any schemas, Rancher will automatically create all of the required schemas during the initial deployment. Change the MySQL user and password as you see fit where the username is located TO 'cattle'@'%' and the password is located IDENTIFIED BY 'cattle'.

Step 5: Configure the HAProxy to use the backend Rancher servers we will deploy in a future step. Replace the listening IP with the load balancer IP, I.E. 10.62.0.90:8080. All connections will terminate for the Rancher instances to the load balancer and load balanced to the backend servers.

Step 6: On each of your three Docker hosts run the following command to create a Rancher HA container. Each Rancher container should use the database that resides in the MySQL Cluster. As directed the cluster sits behind a load balancer with the IP address 10.1.0.1. For each Docker host the IP address 10.1.0.21 will be unique and specific to each Docker host.

Step 7: Login to Rancher for the first time and browse to Admin > Settings. Set the URL to 10.1.0.1 where 10.1.0.1 is the load balancer IP address or hostname answering HTTP request for Rancher.

Step 8: From the Rancher top pane menu browse to Infrastructure > Hosts, click Add Host, select Custom, and specify the IP address of one of the Docker host. Copy the script Rancher generated and run on each applicable Docker hosts. Below is a sample of the script.

Step 9: If any Docker host encounter a problem during setup run the below commands to cleanup the Rancher hooks into the Docker host and try again. You should also remove the host from Rancher as well by browsing to Infrastructure > Hosts.

Step 10: From the Rancher top pane menu browse to Stacks > All. You will notice scheduler is only scaled to one container. Click on the scheduler stack once, and then once again. On the left hand pane you will have the ability to scale the stack further to ensure redundant scheduler containers are running on all three Docker container host also running Rancher.

Verify the configuration

Now that the configuration is finished lets verify our Rancher and Docker deployment. From the Rancher top pane menu browse once again to Infrastructure > Hosts. Here you will see all three hosts listed which the same number of containers providing core Infrastructure services and each with a Rancher HA container. If any issues with one or more containers were present the Health Check services will throw and alarm here for one or more containers and/or the hosts.

Related Posts

What is load sharing and why to use it?Load balancing with BGP is not possible in a multihomed environment with two ISPs. BGP selects only the single best path to a destination among the BGP Read more…

What is MySQL cluster and how to use it?MySQL Galera Cluster is a synchronous multi-master cluster, available on Linux only, and only supports the XtraDB/InnoDB storage engines . It is designed to provide high availability Read more…

What are Docker containers and how to use them?Docker is a software technology providing containers. Docker provides an additional layer of abstraction and automation of operating-system-level virtualization on Windows and Linux. Docker uses the resource Read more…