2

I have a small docker swarm running in my office: one 40-core (128GB RAM) and two 8-core (16GB RAM each). When I deploy a service across the swarm, the jobs are running, but they are spread evenly without regard to per-machine capacity.

I started the swarm on the manager with:

docker swarm init
docker swarm update --task-history-limit 2

and on each node:

docker swarm join --token <token-string> <ipaddr:port>

Then I start a service with:

docker service create --detach \
     --mount type=bind,src=/s/mypath,dst=/home/mypath \
     --entrypoint "/home/mypath/myscript.sh arg1 arg2" \
     --name "mystuff" -w /home/mypath myregistry.me.com:5433/myimage

The process works individually. I have not found an indication of assignment weighting or affinity based on node strength.

Ideally, I'd like to be able to say something like one of these:

  1. join the swarm, take no more than n tasks (a bit naïve)
  2. join the swarm, weight my (cpu-)capacity as 0.2 (or 5 on the larger ones)
  3. start this service, assign no more than one task per available core

I'm self-regulating the overall scale of the service with docker service scale, but that doesn't provide any granularity. Is it possible to regulate docker swarm services per node by available resources?

(This may be even more incentive to switch to k8s, which I'm assuming provides functionality along these lines. There are growing pains with learning and the transition that I've been stiff-arming.)

r2evans
  • 580

1 Answers1

1

All that is indeed possible when you create or update a Swarm service.

This falls under "container placement" options in those commands. If it's just resource reservation you're worried about, then look at --reserve-cpu and --reserve-memory. Those will ensure the node has the free cpu or memory avail on a node before tasking each container.

Example: If you need a swarm service to deploy two php replicas, and each needs to make sure it's on a node with 1GB of memory and 1 CPU, then service create --reserve-cpu 1 --reserve-memory 1GB php will only schedule the containers on nodes that the Swarm scheduler knows have that amount of hardware available. If a node only has 2 logical CPU's, then it would never deploy more then 2 replicas of that service on that node.