Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure autoscaling on docker swarm?

I would like to know how to configure this tool to start with a minimum number of nodes and grow to a maximum number of nodes when it is required.

Should I use another tool or can docker swarm solve this for me?

like image 793
Celso Agra Avatar asked Jan 16 '17 02:01

Celso Agra


People also ask

Can Docker swarm auto scale?

Docker swarm does not support the autoscaling concept. You need to use another solution for that, like docker-machine to create machines on your infrastructure and link these to the existing Swarm cluster.

How do you auto scale a Docker container?

To achieve auto-scaling with Docker, you'll need an external tool to add more nodes (docker engine hosts), when needed, to the Docker Swarm cluster and then start new containers on this cluster.

What is the Docker swarm command to scale the existing service?

Description. The scale command enables you to scale one or more replicated services either up or down to the desired number of replicas. This command cannot be applied on services which are global mode. The command will return immediately, but the actual scaling of the service may take some time.


1 Answers

Short answer: There is no easy way to do this with Docker Swarm for now.

Docker Swarm (or Swarm mode) does not support auto-scaling machines out of the box. You'd need to use another solution for that like docker-machine to create machines (with docker) on your infrastructure and link these to the existing Swarm cluster (with docker swarm join).

This will involve a lot of scripting but the idea is to monitor the cluster for CPU / Memory / Network usage (with top or monit) and once it goes beyond a threshold (say 70% of total cluster resources), you trigger a script calling docker-machine to scale up the cluster. Using the same idea you can also scale down by draining and removing nodes (preferably Agent nodes) from the existing swarm cluster once your are below the lower threshold.

You need to make sure you are monitoring for sustained resource usage if you want to use this criteria or you will have your Infrastructure spawning and destroying nodes from the frequent and sudden changes in resource usage.

You can define a lower bound and an upper bound for machines in the cluster to keep things under control.

Note that Swarm requires at least 3 Manager nodes (recommended 5) to maintain a quorum for the Distributed Consensus algorithm. So the minimum recommended lower bound is 5 nodes (which you can extend with Agent nodes as resources are incrementally being used by services).

To some extent, you can also take a look at Docker InfraKit or Terraform for Infrastructure automation and Health monitoring.

Update: There is now a promising cross-platform autoscaler that supports Swarm Mode task auto-scaling: Orbiter. Although still nothing out-of-the-box yet for service/machine autoscaling.

like image 58
abronan Avatar answered Sep 18 '22 23:09

abronan