Is it possible to auto-scale the number of replicas of a service when using Swarm?

Let’s say I have a service that I start with three replicas. At some point, three replicas can’t keep up with the demand so I need to add a fourth. I know that I can increase the number of replicas using the CLI or the service API, but is there a way to configure the service or Swarm to do this automatically based on the system load or on the number of workers in the Swarm? What I want to achieve is that the service will keep adding replicas until there are enough replicas to handle the system load, without having to manually initiate a request to increase the replica count. In this scenario, the number of worker nodes would be scaled separately (likely using an AWS auto-scaling group).

3 Likes

I’m see this exact limitation with the swarm. It would be awesome if swarm mode would support this out-of-the-box. I also see that the docker is embracing kubernetes. wondering whether docker expect us to move to kubernetes for auto-scaling instead of swarm. swarm has been there for some time now. I feel that it is high time for docker to introduce auto-scaling on swarm. Is there open-source initiative that we can work with to achieve this behaviour.

We needed autoscaling based on metrics stored in prometheus. We built a service which uses docker API to scale based on metrics from prometheus https://github.com/sahajsoft/docker-swarm-service-autoscaler