How does Docker Swarm load balance?

2019-06-18 04:50发布

I have a cluster of 10 Swarm nodes started via docker swarm join command

If i want to scale a docker instance to 15 via

docker service create --replicas 15 

how does docker swarm know where to start the container?

is it round-robin or does it take into consideration of compute resource (how much cpu/mem being used)?

1条回答
该账号已被封号
2楼-- · 2019-06-18 05:21

When you create a service or scale it in the Swarm mode, scheduler on Elected Leader (one of the managers) will choose a node to run the service on. There are 3 strategies currently available to the leader.

  • spread
  • binpack
  • random

The spread and binpack strategies compute rank according to a node’s available CPU, its RAM, and the number of containers it has. The random strategy uses no computation. It selects a node at random and is primarily intended for debugging.

Under the spread strategy, Swarm optimizes for the node with the least number of containers. The binpack strategy causes Swarm to optimize for the node which is most packed.

Swarm uses spread by default. Keep in mind you can Constraint Containers on specific nodes too.

It's not possible to set strategies in docker version 1.12.1 (Latest release to posting date)

查看更多
登录 后发表回答