Monthly Archives: November 2016

Rancher: Running custom Express application

Introduction

In this post, we set up a Rancher cluster and in this one we installed a default WordPress application on it. Though this was a very simple example, it gave us a good view on how to work with Rancher. In this post, we are continuing from where we left of and we’ll install a customer application on the Rancher platform.

If you are a regular visitor of my blog, you will surely know that I have created some sample applications in the past. Rather than developing something completely from scratch, let’s re-use what we have already created in the past. Have a look at this post to know more about the application. We will install an Express application that simply exposes an API. Consuming this API, it will return a text on our screen. Easy! But sufficient to show the principles of running a custom application.

Launching custom application

Go to the Rancher UI, and click on ‘Add Stack’:

rancher2

Next, fill in all details. Pay particular attention to the docker-compose.yml file. Basically, you tell Rancher to download the image wiwa1978/ubuntu-express-app and expose it on port 3000 (note that the app internally is listening to port 3001, so therefore we have the portmapping 3000 to 3001)

rancher1

It will take some time but eventually you will see that the application is active.

rancher3

To see on which host the container is running, go to the Infrastructure tab in Rancher. In our case, the Express application container is running on Rancher-Node-01:

rancher4

To find the IP address that is used for the application, go to Stacks and click on the + sign next to Express Application. You will then see the container. Click on the information icon next to it and a screen will appear on which you will see the exposed IP address.

rancher6

Eventually, open the browser and verify if it’s working properly. Of course it is 🙂

rancher5

Scaling the app

Rancher also offers the possibility to scale the application. It will simple create more container instances and run them over the different hosts. To do this, click on the + sign in the scale section (see screenshot)

rancher7

You will see that in our case, the container was scheduled on the Rancher-Node-02 host:

rancher8

In the previous post, we had already explained the difference between a Docker-compose file and a Rancher-compose file. This is another opportunity to see the difference, have a look at below screenshot:

rancher9

You will see that the Rancher-compose file is adding the scale attribute, which is something that is not supported by native Docker-compose. This is just a simple example of the extensions that Rancher-compose is used for. Other extensions are related to loadbalancers for instance.

That’s it for now. Thanks for reading and hope to see you back in future.

Rancher: Installing WordPress from catalogue

Introduction

In this post, we set up a simple Rancher cluster on Virtualbox. Enough to get started and to run our first service on top of this cluster. This post will describe how to setup WordPress on Rancher. Reading this tutorial is probably going to take you more time than do it, so I encourage you to do it on your own system.

Where we left off in the last post

In the previous Rancher post, we created a Rancher environment consisting of three servers. One server to host the Rancher software, and two additional hosts for the workloads/containers.

rancher-wp-catalog-7

Service Catalogue

In January 2016, Rancher added a service catalogue feature to its product. Rancher Catalog is a standalone service that is integrated into the Rancher UI. The application templates are built on top of docker-compose.yml files and augmented by the rancher-compose.yml files. Compose files can be modified by defining configuration questions in the rancher-compose.yml which ask the user for information at the time of deployment that then modifies the docker-compose file with the injected configuration changes.

Below is a view on this service catalogue. These templates are versioned and maintained on Github.

rancher-wp-catalog-1

Installing WordPress

Installing WordPress is as easy as searching it in the service catalogue and fill out some parameters. See screenshot below:

rancher-wp-catalog-6

To better understand this, let’s have a look at the Docker file and the Rancher file (both can be found here)

The docker-compose.yml file is consisting of two containers, one for the WordPress application and one for the Maria Database.

wordpress:
  image: wordpress
  links:
    - db:mysql
  ports:
    - ${public_port}:80

db:
  image: mariadb
  environment:
    MYSQL_ROOT_PASSWORD: example

The rancher-compose.yml file is really to be seen as a Rancher specific file to augment the docker-compose.yml file with customer specific information. For instance, in below snippet you can see that a variable (for the public port) is asked to the customer. If you have a look at the below screenshot, you indeed see in the WordPress application configuration that this is a text field to fill in.

.catalog:
  name: "Wordpress"
  version: "v0.1-educaas1"
  description: "Blog tool, publishing platform and CMS"
  uuid: WordPress-0
  minimum_rancher_version: v0.51.0
  questions:    
    - variable: public_port
      description: "public port to access the wordpress site"
      label: "Public Port"
      required: true
      default: "80"
      type: "int"
wordpress:

rancher-wp-catalog-2

In below screenshot, you see that Rancher is deploying both containers on the cluster. The internal Cattle orchestration tool is determining where the containers are run.

rancher-wp-catalog-3

Eventually, when finished, you will find two active containers.

rancher-wp-catalog-4

The result

Going through these steps, will finally get you a working WordPress site. In order to test, click on the little information icon next to the WordPress container (in the previous screenshot this is visible). A (kind of) pop up screen will appear where you can find the IP address and port where our WordPress application is running. Go to that IP address with your browser. The screenshot below is just a simple confirmation that WordPress is installed successfully.

rancher-wp-catalog-5

Rancher: Getting started

Introduction

Containers are causing a real revolution. Docker is great (although I’m starting to see some decay as well) but Docker is not always as straightforward as you might think. It’s hard to manage millions of Docker containers, it’s hard to setup networking properly, …. Since release 1.12, there are some improvements though. In any case, I already wanted to experiment quite some time with Rancher. I tried it in their very early days, I loved the concept, but I guess it was too early days back then as I could not get it to work properly.

Maybe let’s touch on what Rancher really is. Rancher is an open source platform for deploying and managing containers in production (it is built specifically for running Docker containers in production environments). It offers storage management, DNS, health monitoring, load balancing, resource management and more.

In essence, Rancher has two aspects:

  1. A user interface: that help you visualize your containers and the infrastructure they are running onto
  2. An orchestration engine (Cattle): that will take care of deploying and managing workloads across a potentially heterogeneous infrastructure

Note: the also just released support for Kubernetes, Docker Swarm and Mesos. Not sure what this means for the Cattle part of the solution.

Pay a visit to their website for more elaborate information and tutorials. Aim for this post is merely to get started with Rancher.

Create a Rancher server

To start, we will create a new server to host the Rancher server (the user interface and the orchestration engine) on. This server will run RancherOS. In the below snippet we basically create the host and install RancherOS on top of it.

WAUTERW-M-G007:Technologies wauterw$ docker-machine create -d virtualbox --virtualbox-boot2docker-url https://releases.rancher.com/os/latest/rancheros.iso RancherOS
Running pre-create checks...
(RancherOS) Boot2Docker URL was explicitly set to "https://releases.rancher.com/os/latest/rancheros.iso" at create time, so Docker Machine cannot upgrade this machine to the latest version.
Creating machine...
(RancherOS) Boot2Docker URL was explicitly set to "https://releases.rancher.com/os/latest/rancheros.iso" at create time, so Docker Machine cannot upgrade this machine to the latest version.
(RancherOS) Downloading /Users/wauterw/.docker/machine/cache/boot2docker.iso from https://releases.rancher.com/os/latest/rancheros.iso...
(RancherOS) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
(RancherOS) Creating VirtualBox VM...
(RancherOS) Creating SSH key...
(RancherOS) Starting the VM...
(RancherOS) Check network to re-create if needed...
(RancherOS) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with rancheros...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env RancherOS

As usual (with Docker-Machine), we need to point our environment to the newly created server. All commands executed thereafter will effectively run on that server.

WAUTERW-M-G007:Technologies wauterw$ eval $(docker-machine env RancherOS)

Install Rancher server

Next, we will install Rancher server. You can refer to this link or follow this tutorial.

WAUTERW-M-G007:Technologies wauterw$ docker run -d --restart=unless-stopped -p 8080:8080 rancher/server
Unable to find image 'rancher/server:latest' locally
latest: Pulling from rancher/server
96c6a1f3c3b0: Pull complete
ed40d4bcb313: Pull complete
b171f9dbc13b: Pull complete
ccfc4df4fbba: Pull complete
9e4d5a1238bb: Pull complete
f986ba0d224d: Pull complete
303d9649bb89: Pull complete
56825bfb5bb7: Pull complete
86a35696481e: Pull complete
eb2848176ff4: Pull complete
fabbcc718243: Pull complete
35489637da84: Pull complete
5c005e2df0e8: Pull complete
64ba16c4c9f4: Pull complete
Digest: sha256:d5a798d1274bcf6813fc9866660dc8559b7e17cdce47608bce28d134bd4f2dc1
Status: Downloaded newer image for rancher/server:latest
48d344bdb17a5873dfd04ff3dc1aad636b3fc19e4c149b778c7aeaadf986500e

The Rancher server is available on port 8080 (as indicated in the docker run command). In order to see the user interface, we need to know the IP address of the host we just created. Luckily this is extremely easy with docker-machine.

WAUTERW-M-G007:Technologies wauterw$ docker-machine ip RancherOS
192.168.99.100

If all went well, going to http://IP_ADDRESS_HOST:8080, you should see something similar to the below screenshot.

rancher1

Adding hosts to Rancher server

Hosts will run the containers. First, create the hosts with docker-machine. We have done this in the previous section, but let’s repeat it once more (only for the first host, the second host is left for the reader)

WAUTERW-M-G007:~ wauterw$ docker-machine create -d virtualbox --virtualbox-boot2docker-url https://releases.rancher.com/os/latest/rancheros.iso Rancher-Node-01
Running pre-create checks...
(Rancher-Node-01) Boot2Docker URL was explicitly set to "https://releases.rancher.com/os/latest/rancheros.iso" at create time, so Docker Machine cannot upgrade this machine to the latest version.
Creating machine...
(Rancher-Node-01) Boot2Docker URL was explicitly set to "https://releases.rancher.com/os/latest/rancheros.iso" at create time, so Docker Machine cannot upgrade this machine to the latest version.
(Rancher-Node-01) Downloading /Users/wauterw/.docker/machine/cache/boot2docker.iso from https://releases.rancher.com/os/latest/rancheros.iso...
(Rancher-Node-01) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
(Rancher-Node-01) Creating VirtualBox VM...
(Rancher-Node-01) Creating SSH key...
(Rancher-Node-01) Starting the VM...
(Rancher-Node-01) Check network to re-create if needed...
(Rancher-Node-01) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with rancheros...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env Rancher-Node-01

Then point the environment to this node:

eval $(docker-machine env Rancher-Node-01)

Next step will be done in the Rancher UI. In order to add hosts to Rancher, just follow the instructions in the UI. More in particular, click on ‘Add hosts’ (see screenshot below)

rancher3

Then, fill in the details in the “Custom” method:

rancher2

Next, ssh into the server (and see how the prompt changes) and run the command that you copied from the Rancher ‘Add Hosts’ UI:

WAUTERW-M-G007:~ wauterw$ docker-machine ssh Rancher-Node-01
[docker@Rancher-Node-01 ~]$ sudo docker run -e CATTLE_HOST_LABELS='Name=Rancher-node-01'  -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.0.2 http://192.168.99.100:8080/v1/scripts/BF48C4313C4967A7A57F:1478541600000:hxTYKEVGoDwndRRU9UAFrxTzKo
Unable to find image 'rancher/agent:v1.0.2' locally
v1.0.2: Pulling from rancher/agent
5a132a7e7af1: Pull complete
fd2731e4c50c: Pull complete
28a2f68d1120: Pull complete
a3ed95caeb02: Pull complete
7fa4fac65171: Pull complete
33de63de5fdb: Pull complete
d00b3b942272: Pull complete
Digest: sha256:b0b532d1e891534779d0eb1a01a5717ebfff9ac024db4412ead87d834ba92544
Status: Downloaded newer image for rancher/agent:v1.0.2
8cb6557b9671b9209be6a7dc0ba6fc254b6d81feb3274c7c8212d5aaf67afd19

It will take a while to install the Rancher agent on the host, but eventually when it finishes, you will see in the Rancher UI that the host has been added. See below screenshot.

rancher4

Repeat all the steps for the second host and you will see the following:

rancher5

That’s it, just wanted to show how to install a Rancher server and add some hosts to it. In future posts, we will surely look into running containers on these hosts and look into setting up multi-cloud environments.

See you later!