• Home  / 
  • Divers
  •  /  Load balancing CouchDB with HAProxy and Tutum

Load balancing CouchDB with HAProxy and Tutum

By KrustyHack / last year

Presentation

Tutum

For those who do not know the Tutum platform, it is a platform that allows the deployment of Docker containers in the cloud. See, it’s worth it: https://tutum.co. Registration is free for now and will subsequently remain at the end of the beta.

HAProxy

HAProxy is a high performance load balancer tcp/http: http://www.haproxy.org/.

CouchDB

CouchDB is a NoSQL database that allows the storage of data via JSON documents: http://couchdb.apache.org/.

Creation of a new Tutum node

First we prepare our Tutum node (our server which will host our containers Docker). Here several options are available to us: use cloud services available in Tutum such as DigitalOcean, AWS,… or then bring ourselves a node. Here we will use DigitalOcean.

tutum-node-create

Remember to tag your Tutum node to be able to deploy services on it. I have tagged my node couchdb.

Once the node is ready, you can go to the next steps.

Our CouchDB service creation

We create our CouchDB service via the Tutum interface.

Selecting Docker image

tutum-service-create-1

Here select tutum/couchdb.

Image setting

tutum-service-create-2

I modified a few options like autorestart. You can also (but I forgot in my screenshot) scale the number of containers to deploy: Update the option Number of containers to 3.

Fill the option Deploy tags with the tag you gave to our Tutum node.

Volume setting

I’ve dropped setting up the environment variables because I changed nothing. So passing to the volumes.

tutum-service-create-3

Add a persistent volume in Host path, and then click Create and deploy to deploy your service.

The CouchDB service is deployed

tutum-service-create-4

And now, our 3 containers are ready.

Our HAProxy service creation

Same thing as the CouchDB service except that we will add a few more options.

Selecting Docker image

tutum-service-create-5

Here select tutum/haproxy.

Image setting

tutum-service-create-6

I changed the name of the service and I’ve set the port mapping by publicly publishing the port 80 and 1936 (the 1936 is for HAProxy stats interface).

Fill the option Deploy tags with the tag you gave to our Tutum node.

Link CouchDB service to HAProxy service

We must link our CouchDB service to our service HAProxy. Nothing is simpler with Tutum.

tutum-service-create-7

Just unroll the Link services at the top menu and select your couchdb service. A link will be created in the table just below.

You can then immediately deploy the service, no need for volumes.

The HAProxy service is deployed

Our load balancer container is up!

tutum-service-create-8

We test our installation

Note that you can access your server either via public IP or Tutum FQDN. Example of Tutum FQDN: http://xxxxxxxx-yyyyyyy.node.tutum.io/. You will find it on the Nodes on the Tutum interface.

Go to http://FQDN/ and enjoy! Your CouchDB are load balanced.

╭─root@krustyhack ~.  
╰─➤ curl http://FQDN/
{"couchdb":"Welcome","uuid":"c9788f9ee479cdd316ad081af8ad9d6e","version":"1.5.0","vendor":{"name":"Ubuntu","version":"14.04"}}
╭─root@krustyhack ~  
╰─➤  curl http://FQDN/
{"couchdb":"Welcome","uuid":"4f9cccb59f794b668db17da7ca1f78d6","version":"1.5.0","vendor":{"name":"Ubuntu","version":"14.04"}}
╭─root@krustyhack ~  
╰─➤  curl http://FQDN/
{"couchdb":"Welcome","uuid":"484c4c9dd8173340534bdf5052d2c96a","version":"1.5.0","vendor":{"name":"Ubuntu","version":"14.04"}}

You can also access the HAProxy stats: http://FQDN:1936. The login/password: stats/stats.

haproxy-stats

Even more

And the fun with Tutum is that if you change your CouchDB container scale, by adding 2 containers for example, HAProxy will automatically make the link with the new containers and load balance them. Magic!

Leave a comment: