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?
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?
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 (withdocker swarm join
).This will involve a lot of scripting but the idea is to monitor the cluster for CPU / Memory / Network usage (with
top
ormonit
) and once it goes beyond a threshold (say 70% of total cluster resources), you trigger a script callingdocker-machine
to scale up the cluster. Using the same idea you can also scale down by draining and removing nodes (preferablyAgent
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 withAgent
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.
Scaling up is pretty easy. You can just keep on scheduling containers when needed. Then you just create a script that looks for pending container and scales up the cluster. For example if you're using the official CloudFormation template on aws for swarm, you can just change the desired number on the autoscaling group. An example iteration script could looks like this: