How to Build a Private Cloud Infrastructure Using Rancher & Docker

How to Build a Private Cloud Infrastructure Using Rancher & Docker

Your Step-by-Step DevOps Guide To Building Your Own Robust Private Cloud

In this step-by-step tutorial, we’re going to walk you through the exact process K&C’s DevOps consultants use to build a private cloud in a data centre using a Docker and Rancher stack. A hybrid cloud set-up is increasingly common, especially at Enterprise level, when data sensitiviy and other security concerns can often mean certain loads simply cannot use a public cloud facility.

Why Build A Private Cloud?

But there are a number of others reasons why a private cloud facility may be either a necessity or preference. For DevOps teams, a private cloud may be used as a development and testing environment as part of a CI/CD pipeline.

Private clouds can also be used to keep running legacy application that it doesn’t make sense to update for compatibility with a public cloud platform. A private cloud can also be fully customised to optimally run specific workloads, especially those involving big data.

Whatever your reasons are for building a private cloud environment, for us at K&C, it is mainly a development and testing stage in a DevOps CI/CD pipeline, this step-by-step tutorial should provide a great starting point for how to go about it. You will need a solid foundational knowledge of Docker and Rancher to build your own private cloud, even with the guidance of the instructions below.

 

Building a private cloud with a Docker and Rancher Stack

DevOps Rancher and Docker Stack To Build Your Private Cloud

We will use the following stack to build our data centre-based private cloud:

Named (round-robin) — Balancing by DNS
NGINX — Web server for proxying requests for a web application
Docker — Software for automation of application deployment and management within the virtualization environment at the operating system level
Docker compose — A tool for starting and connecting to multiple Docker containers
Docker registry — Software for storing Docker images
Rancher — Rancher Labs develops software which allows easy deployment and management of containers within any organization operating on any infrastructure
Rancher compose — Operates on the principle of Docker compose, serves for activation of the Rancher functions
Consul — A utility for Service Discovery and Key/Value Storage
Jenkins — A continuous integration tool written in Java

Building The Basic Cloud Infrastructure

To build the basic infrastructure (without NA), we will need the following:

Name

IP                               DNS
WebServer
192.168.11.140        web.cloud.infra
CloudMaster
192.168.11.72          master1.cloud.infra
CloudClient1
192.168.11.73          ci1.cloud.infra
CloudClient2      192.168.11.132        ci2.cloud.infra

 

* The IPs shown were taken from a real system and are required to match screen shots.

RANCHER OPERATION SCHEME

Rancher operation scheme

1. Setting up a local DNS

The cloud is built within our network, for which purpose a separate zone shall be created.

 

Edit the configuration file named

Now create a zone file:

2. Setting up a master server

And restart Named

DNS has been set up, so proceed to creating a master server

The master server will accommodate: 


– Rancher-server
– Consul-server
– Jenkins 

 

Start up the container with Rancher

Our Rancher server is available at https://master1.cloud.infra:8080.

 

Let’s set up authorization: 

 

1. Admin -> Access Control
2. Select LOCAL 

3. Add a new user

 

 

Set up environments:

 

1. Go to the tab: Default
2. Click: Add Environment
3. Select: Cattle
4. Type the name and add users 

Setting up your own registry

 

1. Go to the tab Infrastructure -> Registries

2. Select: Custom
3. Insert your values 

Create an API key

1. Go to the tab: API
2. Generate and write down your values 

Create an API Key - private cloud set-up using Docker and Rancher

Let’s finish with Rancher for the time being and come back to it when setting up clients

 

Start up the container with consul-server

Consul is (will be) available at https://master1.cloud.infra:8500

Consul-server in private cloud set-up

Start Jenkins

Jenkins is (will be) available at https://master1.cloud.infra:32769

3. Setting up clients

Start up two Docker containers on CloudClient1 and CloudClient2

– Rancher client
– Consul registrator 

To start Rancher client, go to Rancher master:

1. Go to Infrastructure -> Hosts

2. And click: Add Host
3. Enter the external IP of the server in item 4
4. Copy the content of item (from) 5

Rancher master when building a private cloud

Start up containers with Rancher and Consul on CloudClient1

Do the same on CloudClient2 but change the IP addresses

If everything has been successfully completed, then we will see our servers in Rancher

* Please, ignore the launched services

4. Setting up a project

To create a project in Rancher, you need to create a docker-compose v1 file, add data obtained from the API, and download Rancher-compose.

Rancher does not collect projects from Dockerfile, but downloads them from the registry. For this reason, collect either locally or from any host

Create a homepage project:

Also, create a simple build script

Export global variables

And download Rancher-compose (Link in the bottom right-hand corner in Rancher)

Add the project to Rancher

Start the project

If everything has been successfully completed, then we will see the following in Rancher:

Rancher view in private cloud build

We will also see the following in Consul:

Consul view in private cloud build

5. Setting up a WEB server

Install NGINX and download consul-template

Create a Consul-template for NGINX

Start NGINX and consul-template

Now, Consul-template will keep track of changes in Consul-server and rewrite data to the NGINX configurations.

6. Jenkins CI

The final tweak in our cloud is adding continuous integration.

For this purpose, add values obtained from the API to the configuration in Jenkins

Create a Job and insert the following in the shell exec item

Your Private Cloud Is Ready For Project Deployment

Once you have worked your way through the step-by-step process, your private cloud is ready to run. Your cloud project can now be deployed at the click of a button. The containers are up on the least loaded hosts and linked between each other via the internal Rancher network.

I have not gone into full detail on all the capabilities of this DevOps private cloud set-up but you should have a good overview of its core capabilites.

Add comment

E-mail is already registered on the site. Please use the Login form or enter another.

You entered an incorrect username or password

Sorry that something went wrong, repeat again!
EN DE
Contact us