Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Docker Swarm load balance?

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)?

like image 552
ealeon Avatar asked Oct 05 '16 15:10

ealeon


People also ask

How does a docker swarm work?

A Docker Swarm is a group of either physical or virtual machines that are running the Docker application and that have been configured to join together in a cluster. The activities of the cluster are controlled by a swarm manager, and machines that have joined the cluster are referred to as nodes.

Do containers perform load balancing?

Container-native load balancing is always used for internal GKE Ingress and is optional for external Ingress. The Ingress controller creates the load balancer, including the virtual IP address, forwarding rules, health checks, and firewall rules.

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.

Is docker swarm being deprecated?

Docker Swarm is not being deprecated, and is still a viable method for Docker multi-host orchestration, but Docker Swarm Mode (which uses the Swarmkit libraries under the hood) is the recommended way to begin a new Docker project where orchestration over multiple hosts is required.


1 Answers

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)

like image 166
Farhad Farahi Avatar answered Oct 06 '22 16:10

Farhad Farahi