[클라우드/Docker 기본(20) - Docker Swarm Mode(4) : 가용성]

SooYeon Yeon·2022년 9월 13일
0

클라우드 Docker

목록 보기
21/24

가용성

Active는 노드가 컨테이너를 동작시키고 생성할 수 있는 준비가 된 상태

drain : 컨테이너를 해당 노드에 배치시키지 않는다. 해당 노드에서 동작중인 모든 컨테이너는 중지됨

pause : 컨테이너를 해당 노드에 배치시키지 않는다. 컨테이너가 일시중지된다.

가용성 실습

  • 서비스 배포
rapa@manager:~$ docker service create --name test1 --replicas 3 --constraint node.role==worker -p 8001:80 nginx
  • 서비스 확인
rapa@manager:~$ docker service ps test1
ID             NAME      IMAGE          NODE      DESIRED STATE   CURRENT STATE            ERROR     PORTS
d44gxqhsiwcr   test1.1   nginx:latest   worker3   Running         Running 30 seconds ago             
k1kt8z9udwf9   test1.2   nginx:latest   worker2   Running         Running 30 seconds ago             
me86ba1adye4   test1.3   nginx:latest   worker1   Running         Running 30 seconds ago

현재 worker1,2,3에 모두 동작하고 있는 상태이다.

  • worker3의 가용성을 drain으로 변경
rapa@manager:~$ docker node update --availability drain worker3
worker3
  • 변경 되었는 지 확인
rapa@manager:~$ docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
mmq3j418myp0x5pktz3o0k1jt *   manager    Ready     Active         Leader           20.10.17
qk27035jk5cd7bazkd838dxs5     worker1    Ready     Active                          20.10.17
o9obccagttlfcjkqwczppimtd     worker2    Ready     Active                          20.10.17
hripanq8twelfv6k6jtlvntp1     worker3    Ready     Drain                           20.10.17
  • 서비스 확인
rapa@manager:~$ docker service ps test1
ID             NAME          IMAGE          NODE      DESIRED STATE   CURRENT STATE             ERROR     PORTS
mlvfrg16v8j9   test1.1       nginx:latest   worker2   Running         Running 44 seconds ago              
d44gxqhsiwcr    \_ test1.1   nginx:latest   worker3   Shutdown        Shutdown 47 seconds ago             
k1kt8z9udwf9   test1.2       nginx:latest   worker2   Running         Running 2 minutes ago               
me86ba1adye4   test1.3       nginx:latest   worker1   Running         Running 2 minutes ago

worker3은 Shutdown이 되었고, 3은 drain 상태이기 때문에 worker3에는 배치되지 않고 worker2에 2개가 배치 된 것을 볼 수 있다.

  • test1에서 scale을 늘려 4개가 돌아가도록 늘려보자
rapa@manager:~$ docker service scale test1=4
test1 scaled to 4
overall progress: 4 out of 4 tasks 
1/4: running   
2/4: running   
3/4: running   
4/4: running   
verify: Service converged
rapa@manager:~$ docker service ps test1
ID             NAME          IMAGE          NODE      DESIRED STATE   CURRENT STATE            ERROR     PORTS
mlvfrg16v8j9   test1.1       nginx:latest   worker2   Running         Running 2 minutes ago              
d44gxqhsiwcr    \_ test1.1   nginx:latest   worker3   Shutdown        Shutdown 2 minutes ago             
k1kt8z9udwf9   test1.2       nginx:latest   worker2   Running         Running 3 minutes ago              
me86ba1adye4   test1.3       nginx:latest   worker1   Running         Running 3 minutes ago              
x2y9q2yrd9hz   test1.4       nginx:latest   worker1   Running         Running 26 seconds ago

worker3은 drain상태가 되어있개 때문에 worker1에 2개, worker2에 2개가 배치 되어있다.

  • worker3의 가용성을 다시 active 상태로 변경
rapa@manager:~$ docker node update --availability active worker3
worker3
rapa@manager:~$ docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
mmq3j418myp0x5pktz3o0k1jt *   manager    Ready     Active         Leader           20.10.17
qk27035jk5cd7bazkd838dxs5     worker1    Ready     Active                          20.10.17
o9obccagttlfcjkqwczppimtd     worker2    Ready     Active                          20.10.17
hripanq8twelfv6k6jtlvntp1     worker3    Ready     Active                          20.10.17
  • 상태 확인
rapa@manager:~$ docker service ps test1
ID             NAME          IMAGE          NODE      DESIRED STATE   CURRENT STATE            ERROR     PORTS
mlvfrg16v8j9   test1.1       nginx:latest   worker2   Running         Running 4 minutes ago              
d44gxqhsiwcr    \_ test1.1   nginx:latest   worker3   Shutdown        Shutdown 4 minutes ago             
k1kt8z9udwf9   test1.2       nginx:latest   worker2   Running         Running 6 minutes ago              
me86ba1adye4   test1.3       nginx:latest   worker1   Running         Running 6 minutes ago              
x2y9q2yrd9hz   test1.4       nginx:latest   worker1   Running         Running 2 minutes ago

아직 worker1에 2개, worker2에 2개가 그대로 동작하고 있다(worker3은 동작X)

이럴 경우 sclae을 조정한다. scale 1 → scale 3 으로

rapa@manager:~$ docker service scale test1=1
test1 scaled to 1
overall progress: 1 out of 1 tasks 
1/1: running   
verify: Service converged 
rapa@manager:~$ docker service scale test1=3
test1 scaled to 3
overall progress: 3 out of 3 tasks 
1/3: running   
2/3: running   
3/3: running   
verify: Service converged
  • 각각 하나씩 배치가 되어 있는 상태로 바뀐다.
rapa@manager:~$ docker service ps test1
ID             NAME          IMAGE          NODE      DESIRED STATE   CURRENT STATE            ERROR     PORTS
mlvfrg16v8j9   test1.1       nginx:latest   worker2   Running         Running 6 minutes ago              
d44gxqhsiwcr    \_ test1.1   nginx:latest   worker3   Shutdown        Shutdown 6 minutes ago             
s5vpr0q66477   test1.2       nginx:latest   worker3   Running         Running 28 seconds ago             
mfbi5pltlsn7   test1.3       nginx:latest   worker1   Running         Running 28 seconds ago

0개의 댓글