Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limit swarm from creating more than X number of containers per node

is there any to limit swarm from creating for example 20 number of containers per worker. so, one worker wouldn't have more than 20 containers for better QoS (Quality of service), this'll also prevent overcommitting host's resources?

thanks

like image 589
Shashwat shagun Avatar asked Dec 13 '22 20:12

Shashwat shagun


2 Answers

For docker-ce 19.03+, you can simply create/update your service with the --replicas-max-per-node option:

# create service with replicas-max-per-node=10
docker service create --replicas=100 --replicas-max-per-node=10 --name your_service_name your_image_name

# update service with replicas-max-per-node=20
docker service update --replicas-max-per-node=20 your_service_name

read more

UPDATE (2020-04-10)

- Add 3.8 compose version
    Limit service scale to the size specified by the field deploy.placement.max_replicas_per_node

read more

like image 181
kev Avatar answered Dec 16 '22 08:12

kev


You can't exactly say "Limit to 20 containers" per node. If memory is your issue you can look into using limits and reservation in your stack files. This will tell the scheduler to not schedule containers on the node if there isn't enough memory. There are also CPU reservation/limits you can set but that doesn't seem to influence the schedules.

This link on compose is helpful in learning about limits and reservation https://docs.docker.com/compose/compose-file/#resources

  my-java-service:
    image: yourcompany.com/my-java-service:1.1.0
    environment:
      - JAVA_OPTS=-Xmx4096m -Xms4096m -XX:+UseG1GC -XX:+UseStringDeduplication -XX:-TieredCompilation -XX:+ParallelRefProcEnabled
    deploy:
      mode: replicated
      placement:
        constraints:
          - node.labels.env.lifecyle==prod
      replicas: 40
      resources:
        reservations:
          memory: 5120M
      update_config:
        delay: 1m
        parallelism: 1
      restart_policy:
        condition: none
like image 22
Tim Razik Avatar answered Dec 16 '22 08:12

Tim Razik