Couchbase Cluster on Docker Swarm using Docker Compose and Docker Machine

This blog post will explain how to create and scale a Couchbase Cluster using full armor of Docker – Docker Machine, Docker Swarm and Docker Compose.

Here is what we’ll do:

  • Create a 3-node Docker Swarm Cluster using Docker Machine
  • Run a Couchbase instance on two nodes
  • Create a cluster
  • Rebalance the cluster
  • Scale and rebalance the cluster again

couchbase-docker-swarm-0

Docker Swarm Cluster using Consul

Create a three-node Docker Swarm cluster using Docker Machine:

Provision a Swarm cluster with Docker Machine provide more details about why and what’s done in this script. Here is a summary:

  • Create a Docker Machine and run Consul for service discovery
  • Create three Docker Machines – one for Master and two for Worker nodes.Each machine is configured to be part of a Swarm cluster using --swarm. It also uses the Consul service discovery specified using --swarm-discovery.

Couchbase Nodes on Docker Swarm

Create two instances of Couchbase using Docker Compose:

arungupta/couchbase image is used here. This image is defined at Couchbase Docker Image. It uses the Official Couchbase Docker Image add configures it as explained:

  1. Setups memory for Index and Data
  2. Configures the Couchbase server with Index, Data, and Query service
  3. Sets up username and password credentials
  4. Loads the travel-sample bucket

Compose file uses host network. This is equivalent to using --net=host on docker run CLI. It allows the container to use the host networking stack. It also limits only a single Couchbase container to run on a single Docker Machine. So this means that our Couchbase cluster can scale based upon the number of Docker Machines – 3 in our case.

The exact command to use this Compose file is:

There are three nodes in the Docker Swarm cluster. The default scheduler strategy is spread and so the containers will be spread on different hosts.

This is evident by docker ps:

Note, one Couchbase server is running on swarm-node-01 and another on swarm-node-02. Each server is configured with an administrator username Administrator and password password.

Find out IP address of the Docker Machine:

If you have jq installed then IP address can be conveniently found as:

Couchbase Cluster on Docker Swarm

All Couchbase server nodes are created equal. This allows the Couchbase cluster to truly scale horizontally to meet your growing application demands. Independently running Couchbase nodes can be added to a cluster by invoking the server-add CLI command. This is typically a two step process. The first step is adding one or more nodes. The second step then rebalances the cluster where the data on the existing nodes is rebalanced across the updated cluster.

In our case, a single Couchbase container is running on each Docker Machine. Lets pick IP address of any one Couchbase node, and add IP address of the other node:

Couchbase Web Console for both the nodes will show a similar output:

couchbase-docker-swarm-1

couchbase-docker-swarm-2

This shows that the two nodes now form a cluster, and needs to be rebalanced.

Rebalance Couchbase Cluster

Now, lets rebalance the cluster:

Couchbase Web Console will be updated to show that rebalance is happening:

couchbase-docker-swarm-3

And finally you’ll see a rebalanced cluster:

couchbase-docker-swarm-4

Scale and Rebalance Couchbase Cluster

Scale the Couchbase cluster:

Check that the container is running on a different Docker Machine:

As mentioned earlier, scaling a Couchbase cluster is a two-step process. This is so because typically you’ll add multiple servers and then rebalance the cluster. However, in cases where you only need to add a single Couchbase node and then rebalance, the rebalance command can be used achieve that.

In our case, this is done as shown:

The rebalanced cluster now looks like:

couchbase-docker-swarm-5

This blog showed how you can easily create and scale a Couchbase Cluster using Docker Swarm, Machine and Compose.

Enjoy!

Further reading …

  • Couchbase Server Developer Portal
  • Couchbase Server Concepts
  • Couchbase Cluster Setup
  • Questions on StackOverflow, Forums or Slack Channel
  • Follow us @couchbasedev
  • Couchbase 4.5 Beta

Source: http://blog.couchbase.com/2016/may/couchbase-cluster-docker-swarm-compose-machine

Create and scale your #Couchbase cluster using #Docker Machine, Swarm and Compose Click To Tweet
Be Sociable, Share!
  • Tweet

2 thoughts on “Couchbase Cluster on Docker Swarm using Docker Compose and Docker Machine

  1. I advise you to check https://writemyessay4me.org/blog/character-analysis out if you want to know more about character analysis. It was useful for me and my friends in college

  2. This article will be useful to students of programmers. But students should not focus on studying a single subject. Therefore, I advise you to visit my site. Best essay writing tips.
    CustomEssayMeister.

Leave a Reply

Your email address will not be published. Required fields are marked *