简体   繁体   中英

Can docker swarm stack distribute services averagely to all nodes?

I have:

  • three 1 swarm manager and 2 swarm working nodes
  • an application cluster that connected to each other

docker-compose.yml

services:
  service1:
    ports:
      - 8888:8888
    environment:
      - ADDITIONAL_NODES=service2:8889,service3:8890
  service2:
    ports:
      - 8889:8889
    environment:
      - ADDITIONAL_NODES=service1:8888,service3:8890
  service3:
    ports:
      - 8890:8890
    environment:
      - ADDITIONAL_NODES=service1:8888,service2:8889

If I run docker stack deploy -c docker-compose.yml server :

  1. swarm manager(service1), swarm node1(service2), swarm node2(service3)

  2. swarm manager(service1、service2、service3), swarm node1(service1、service2、service3), swarm node3(service1、service2、service3)

Which one will be the result?

If it is 2 , how can I deploy like 1 using docker swarm? I need to use docker swarm because I'm also using docker network overlay.

If it is 1 , then how does my services distributed? Is it "averagely" distributed? If true then in what perspective is it "averagely" distributed?

Docker swarm has some logic which it uses to decide which services run on which nodes. It might now be 100% what you expect but they are smart people working on this and might consider things that you don't (such as CPU load, available ram....)

The goals is to spread the load evenly so like your example 1. If some services can for some reason not start on one node (like you use a private registry but didn't specify --with-registry-auth in stack deploy) then the services will all start on those nodes who can run them after failing on the other nodes.

From personal experience I can tell you that it spreads tasks nicely accross the swarm but theres no guarantee where which service ends up.

If you want to force where services run use constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM