---
title: Rancher High-Availability
url: https://blog.octoperf.com/rancher-high-availability/
date: '2016-11-24'
authors:
- gpereira
categories:
- DevOps
tags:
- Docker
- Database
- Rancher
- Proxy
description: Step by step guide to install Rancher High-Availability (multi-nodes).
---

# Rancher High-Availability

This blog post is the last part of a series of three tutorials dedicated to **Rancher High-Availability**. 

We previously installed Rancher single-node using a external databases:

* a [replicated Master-Master MySQL database](https://blog.octoperf.com/mysql-master---master/),
* a [MariaDB Galera Cluster](https://blog.octoperf.com/galera-cluster-for-rancher/).

**This time we will go full HA by installing Rancher on three servers.** 


## Pre-requisites

You need an existing Rancher server (single-node) that uses an external database. You also need from 3 to 5 servers with at least 1GB RAM (8GB recommended) and a load balancer:  

* Rancher Server One available at IP address _1.1.1.1_,
* Rancher Server Two available at IP address _2.2.2.2_,
* Rancher Server Three available at IP address _3.3.3.3_,
* Load Balancer available at IP address _4.4.4.4_.

**All servers must have [Docker](https://www.docker.com/) installed.**

### Firewall configuration

You need a global access for each Rancher server on TCP Ports 22, 80, 443 and 18080.

You need access between Rancher servers :

* to UDP Ports 500, 4500
* to TCP Ports: 2181, 2376, 2888, 3888, 6379

### Heap Size configuration

For larger deployments you may also need to **increase the Rancher Heap Size**. 
That can be done by passing the environment variable `-e JAVA_OPTS="-Xms2048m -Xmx2048m"` when running the rancher/server container.

## Installing the Rancher Load Balancer

**We need a load balancer in front of our 3 Rancher servers.** The HA documentation gives us configuration samples for Nginx, Apache and HAProxy. Let’s give a try to HAProxy. 

Copy the configuration file from [Rancher documentation](https://docs.rancher.com/rancher/v1.2/en//installing-rancher/installing-server/basic-ssl-config/#example-haproxy-configuration) and edit it using you 3 nodes IP addresses:

```sh
global
  maxconn 4096
  ssl-server-verify none

defaults
  mode tcp
  balance roundrobin
  option redispatch
  option forwardfor

  timeout connect 5s
  timeout queue 5s
  timeout client 36000s
  timeout server 36000s

frontend http-in
  mode tcp
  bind *:443 ssl crt /etc/haproxy/certificate.pem
  default_backend rancher_servers

  acl is_websocket hdr(Upgrade) -i WebSocket
  acl is_websocket hdr_beg(Host) -i ws
  use_backend rancher_servers if is_websocket

backend rancher_servers
  server websrv1 1.1.1.1:443 weight 1 maxconn 1024 ssl
  server websrv2 2.2.2.2:443 weight 1 maxconn 1024 ssl
  server websrv3 3.3.3.3:443 weight 1 maxconn 1024 ssl
```

Connect to the _load balancer_ server using SSH and paste the HAProxy configuration in a file named _haproxy.cfg_.

You may also need a SSL certificate. [Generate it](https://www.digitalocean.com/community/tutorials/how-to-implement-ssl-termination-with-haproxy-on-ubuntu-14-04) using the command:

```sh
 sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /root/rancher.key -out /root/rancher.crt
```

And create the .pem file using `cat rancher.crt rancher.key > rancher.pem`

Then run a Docker container for HAProxy:
```sh
docker run -d --name haproxy -v /root/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro -v /root/rancher.pem:/etc/haproxy/certificate.pem:ro haproxy:1.5
```

You can display the logs using the command `docker logs -f haproxy`.

## Exporting the Rancher High-Availability script

Go to the Rancher High-Availability page: 

![Rancher HA Generate Script](https://blog.octoperf.com/img/blog/rancher-ha/rancher-ha-generate-script.png "Rancher HA Generate Script")

1. Copy/paste the IP address of your load balancer into the _Host Registration URL_ field.
2. Copy/paste the content of the _rancher.key_ file into the _Private Key_ field and the content of _rancher.crt_ into _Certificate_.
3. Click on _Generate Config Script_ and on _Download Config Script_.
4. Stop the Rancher container on Rancher Server One (`docker stop <containerID>`).
5. Copy the downloaded script on each node, and execute it:

```sh
sudo bash ./rancher-ha.sh rancher/server:v1.1.4
```

You can display the logs on each node using `docker logs -f rancher-ha`. 
Also you can access each Rancher UI at http://1.1.1.1:1800/ and view the Audit Logs (Admin > Audit Logs) and the HA Environment stack.
   
Wait for all the servers to start (this may take a few minutes). **Finally the Rancher cluster UI should be available** at the IP address of your load balancer https//4.4.4.4/ and should display the High-Availability status:

![Rancher HA Enabled](https://blog.octoperf.com/img/blog/rancher-ha/rancher-ha-enabled.png "Rancher HA Enabled")

## Conclusion

We managed to have multiple Rancher severs working together but **the load balancer is still a Single Point of Failure**. 
If it goes does the whole infrastructure would be unavailable.
