Does max_replicas_per_node affect parallelism in update_config?

Publish date: 2024-05-07

Problem

So far my docker-compse looks like this:

services: nodejs: deploy: replicas: 2 restart_policy: condition: any placement: max_replicas_per_node: 1 update_config: parallelism: 2 delay: 10s order: start-first 

On the first docker stack deploy st my stack looks like this (docker stack ps st modified to fit in):

ID NAME IMAGE NODE DESIRED CURRENT STATE ERROR PORTS py st_nodejs.1 :latest dev Running Running 13 seconds ago hq st_nodejs.2 :latest Running Pending 16 seconds ago "no suitable node (max replica…" 

Lets say I moved the latest tag in my registry and want to update my service with docker-compse pull && docker stack deploy st. Now my stack looks like this:

ID NAME IMAGE NODE DESIRED CURRENT STATE ERROR PORTS qh st_nodejs.1 :latest Running Pending 33 seconds ago "no suitable node (max replica…" py st_nodejs.1 :latest dev Running Running 16 minutes ago nw st_nodejs.2 :latest Running Pending 33 seconds ago "no suitable node (max replica…" hq \_ st_nodejs.2 :latest Running Pending 16 minutes ago "no suitable node (max replica…" 

Question

I think max_replicas_per_node is limiting the update_config.parallelism entry so the result is it can't start a new node, but I did not find any proof about my theory.

Am I right, and is there a better solution?

Goals

  • I want to limit my service to one per node (for now because 2 core machines are to expensive).
  • But if there is one node joining the swarm, it should run one container (replicas: 2 for having max two nodes in the swarm).
  • I also want updates to applied by first starting the new container and then killing the old one (update_config.parallelism: 2).
  • 2

    1 Answer

    It looks like max_replicas_per_node is a hard limit:

    if you think that --max-replicas-per-node settings should be hard limit which cannot be exceed even on rolling upgrade

    In my opinion, the best way seems updating the replicas when the swarm contains more than one node and keeping max_replicas_per_node equal (or greater) to parallelism:

    1 worker node

    deploy: replicas: 1 placement: max_replicas_per_node: 2 update_config: parallelism: 2 order: start-first 

    n worker nodes (n>1)

    deploy: replicas: n placement: max_replicas_per_node: 2 update_config: parallelism: 2 order: start-first 

    ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobXBwZWaDdYCOnaaeq12irrl50Z6npaGTlsBuvMSrZKenlJp6orLFnpqtZaCWv6K4y56joqudYravedSpm5qslWKwsLrFop4%3D