—cpus : 컨테이너가 사용가능한 CPU 리소스 양 지정
—cpus=0.2 : 1개의 CPU 사용중인 경우 CPU의 20%만 사용가능
—cpus=1.5 : 여러개 CPU 사용중인 경우 1.5개 CPU 사용 보장
-m 또는 —memory | 컨테이너가 사용할 수 있는 최대 메모리 크기 지정. 허용되는 최솟값은 4m(4MB) |
---|
stack의 yml 파일에서 CPU, Memory 제약
version: '3.7'
services:
nginx:
image: nginx
deploy:
replicas: 3
placement: # "-" AND "-"
constraints:
- node.labels.region==seoul
- node.labels.customer==lg
resources:
limits: # max
cpus: '0.5' # --cpus
memory: 64M # --memory
reservations: # min
cpus: '0.25'
memory: 32M
restart_policy:
condition: on-failure
max_attempts: 2
environment:
SERVICE_PORTS: 80
networks:
- myovlnet
proxy:
image: dockercloud/haproxy
depends_on:
- nginx
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports: # -p option, attached to ingress network
- "8002:80"
networks: # backend network -> nginx containers
- myovlnet
deploy:
mode: global
placement:
constraints: [node.role==manager]
networks:
myovlnet:
external: true
메모리의 limit:500이면 최대 늘어나도 500까지
메모리의 reservation:250이면 250은 꼭 보장해준다는 뜻
rapa@manager:~/0826$ docker stack deploy -c testweb.yml testweb
Updating service testweb_proxy (id: pqthg74ytflrq6bl93exl4bkd)
image dockercloud/haproxy:latest could not be accessed on a registry to record
its digest. Each node will access dockercloud/haproxy:latest independently,
possibly leading to different nodes running different
versions of the image.
Updating service testweb_nginx (id: 1evyh4nouqz4rqyh41sg251vk)
image nginx:latest could not be accessed on a registry to record
its digest. Each node will access nginx:latest independently,
possibly leading to different nodes running different
versions of the image.
배포하면 수정된 부분이 있는 nginx 부분만 update 됨
apa@manager:~/0826$ docker service inspect testweb_nginx --pretty
...
Labels:
com.docker.stack.image=nginx
com.docker.stack.namespace=testweb
...
Resources:
Reservations:
CPU: 0.25
Memory: 32MiB
Limits:
CPU: 0.5
Memory: 64MiB
Networks: myovlnet
Endpoint Mode: vip