Are services with their own clustering mechanisms suitable for swarm

2/13/2020

I just started learning swarm recently. And I have some questions about the swarm usage scenario.

If I have a simple webserver which response to some restful HTTP requests,swarm seems to be a good choice because if I need to expand my webserver horizontally, I just need to use docker service scale and the swarm will do load balancing for me.

But what about services that have their own clustering mechanism(Redis, elastic search?)? I cannot simply expand the capacity through the docker service scale`.

For instance, I have a Redis service, if I docker service scale redis=2, two separate Redis services are generated. This is obviously not what I need.

Are these services fit for swarm mode?If so, how to config these services in swarm mode? And how to expand it?

-- ppbb
docker
docker-swarm
kubernetes

1 Answer

2/13/2020

Stateful services (e.g. Redis, RabbitMQ, etc...) fit swarm mode.

It's your responsibility though to configure the cluster manually, by some predeploy/postdeploy script or in images entrypoint.

Such reconfiguration should run also after each replica restart regardless the reason: single replica failures and subsequent restarts, restart of all service replicas, scaling of new replicas.

Content of such script/steps may vary between clustering solutions and one should refer to the relevant documentation of each solution. It maybe as simple as putting replicas virtual ips to configuration file or complex ordered steps.

General use cases that fit all solutions are: configure cluster inside service replicas for the first time, connect single replica back to cluster after failure, restart all replicas after failure/valid restart.

Some github projects try to automate the process. For example mariadb-cluster

-- rok
Source: StackOverflow