Skip to Content
Technical Articles

Solr Docker image for master-slave mode

Introduction

If you are like me using Solr in the master-slave mode for so long and looking for a Docker image that supports master-slave mode with simple configuration, then you have come to the right place.

The Docker image allows you to configure Solr in standalone mode, master-slave mode.

If you are planning to use Solr for a brand new implementation, using Solr in cloud mode is the recommended approach. However, for an existing implementation that is on master-slave mode and looking to containerize the application, this image would come in handy.

Currently, only version 7.7.1 is supported, if you are wondering why only this version, Solr 7.7.1 is the supported version in the SAP Commerce version 1905 (which is the latest version as of this writing). The image is created to run in tandem with SAP Commerce instance.

Pull the image

$ docker pull valtechus/solr:7.7.1

Run in standalone mode

$ docker run -it -p 8983:8983 valtechus/solr:7.7.1

Run in master-slave mode

Create and run a master container

$ docker run -it -p 8983:8983 -e CLUSTER=true -e MASTER=true valtechus/solr:7.7.1

Create and run a slave container

$ docker run -it -p 8985:8983 -e CLUSTER=true -e MASTER=false -e SOLR_MASTER_HOST=localhost -e SOLR_MASTER_PORT=8983 valtechus/solr:7.7.1

Master can be accessed at http://localhost:8983/solr and slave can be accessed at http://localhost:8985/solr

Now that a slave container can be created and know it’s master, you can create any number of slaves that your application demands.

Configuration of docker-compose for master-slave mode

docker-compose.yaml can be downloaded from here.

Just run docker-compose up to create and run one master, one slave container from the image.

Run Solr master-slave on Kubernetes

Let’s see how to run this Solr image on Kubernetes, to make it easier, Kubernetes configuration and scripts are made available in a repository You can clone the repository and run scripts to deploy Solr on Kubernetes.


Assumption is that you have Kubernetes setup on your local or on the cloud. If you want a detailed setup of GKE, refer to the detailed blog post here.


Create one master and one slave

You can create a master and a slave by running the following script –

$ git clone https://bitbucket.org/valtechny/solr-master-slave-docker.git
$ cd solr-kubernetes
$ sh kubernetes/solr.sh

You should see the following output when you run ‘kubectl get all -l app=solr

Scale slave pods

If you want to scale up your Solr, you can achieve it by scaling up Solr slave pods. In master salve mode, there will always be one master, so the scaling can only be done on slaves. Execute the below script to scale slave pod replicas to 3 so that StatefulSet will know to increase the number of slave pods to 3 from the current 1 count.

# scales slave pods  to 3
$ sh solr-scale 3

You should see the following output when you run ‘kubectl get all -l app=solr’ and you can notice that the number of slave pods is 3 as opposed to the earlier count of 1.

Access master, slave

You can access master and slave from the internet by exposing master service, slave service via a load balancer. Keep in mind that the load balancer service is subject to billing. Run the below script. All the script is going to do is update the Solr master, slave services from default ClusterIP type to LoadBlanacer, which creates an external IP address.

$ sh kubernetes/solr-lb.sh

It is going to take a few minutes for the external IP addresses to be allocated; until then, you would see a pending state.

Once external IP addresses are allocated, Solr master can be accessed at http://<master external ip>:8983/solr and saves at http://<salve external ip>:8983/solr

If you don’t want to create a separate load balancer for master and salve, Ingress provides a way to just use one IP address and achieve name-based virtual hosting to support multiple domains. For more information on Ingress, refer to this link.

Conclusion

Solr Docker image that supports easy master-slave configuration. Only version 7.7.1 is supported at this time. Sample docker-compose and Kubernetes scripts are included, which helps with deploying the Solr Docker image on Kubernetes. Also, as part of Kubernetes deployment, we looked at the scaling of the slave pods and exposing master, slave to the internet via Kubernetes load balancer service. Kubernetes scripts included can be re-purposed to deploy other Docker images to Kubernetes.

About the Author

Ravi Avulapati – Specializes in Java, J2EE, and frameworks, SAP Commerce (Hybris), Search with Solr, Solution & Enterprise Architecture, Microservices, DevOps, Cloud solutions. Machine learning and deep learning enthusiast.

About Valtech

Valtech is a global full-service digital agency focussed on business transformation with offerings in strategy consulting, experience design & technology services. Valtech is an SAP partner and is an SAP recognized expert in SAP Commerce.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.