Hack and Explore :-)

Menu

Docker Swarm with Elasticsearch Cluster

TL;DR

We use a Docker cluster to launch an Elasticsearch instance as a global service. This will scale our Elasticsearch instance with each machine we add to the cluster. We will set a certain parameters in the Elasticsearch container to launch an Elasticsearch cluster within our Docker cluster.

Context

We created a Docker cluster earlier. We even created an Elasticsearch instance on that cluster. We will be removing that deployment and creating a new instance with clustering functionality.

Removing the current instance

To remove the existing Elasticsearch instance we will be using the following command:

docker service rm elasticsearch

Creating a clustered Elasticsearch instance

To create a new Elasticsearch instance with clustering we will be using the following command:

Here we are adding a few environment variables to tell Elasticsearch that we want to create a cluster. The --mode global option is used to make the instace scalable with the cluster. Another important parameter is endpoint-mode "dnsrr" witch change the container networking mode to DNS round robin. The container parameters after the image configures Elasticsearch to work in cluster mode.

Verification

We can confirm our Elasticsearch cluster by examining the logs of the container. By following these commands we get the logs: