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
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
- Add 3.8 compose version
Limit service scale to the size specified by the field deploy.placement.max_replicas_per_node
read more
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With