반응형
개요
docker service create 명령어에 사용되는 --mode 옵션
구성환경
docker-ce-19.03.5 / CentOS 7.6
1. --mode 옵션
value : replicated(default), global
설명
- replicated(default, 생략가능) : --replicas 옵션의 n 값에 따라 복제될 컨테이너수가 지정 됨
- global : swarm에 가입하는 노드는 기존 생성된 swarm의 service를 승계 받음
예) replicated 옵션(3개의 노드로 이루어진 swarm)
1) swarm master 노드(node1)에서 서비스 생성
shell> docker service create --mode replicated --replicas 5 -p 8080:80 --name my_nginx_1 nginx:latest jsg7tm7ehjg06fttgm33hfy1a overall progress: 5 out of 5 tasks 1/5: running 2/5: running 3/5: running 4/5: running 5/5: running verify: Service converged shell> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c1769d9807f2 nginx:latest "nginx -g 'daemon of…" 16 seconds ago Up 14 seconds 80/tcp my_nginx_1.1.ne3xpnbh7mavxdv4p6sjx51ja shell> |
2) 다른 노드에서 생성된 컨테이너 확인
- node2 에서 생성된 컨테이너 확인
shell> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c57109498d47 nginx:latest "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 80/tcp my_nginx_1.2.3djlsv0toemnjamca27hjn8l2 6193f5e385e5 nginx:latest "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 80/tcp my_nginx_1.4.jdo6gkt14xu36vaeo0o02q3vp shell> |
- node3 에서 생성된 컨테이너 확인
shell> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6cbbff0654d1 nginx:latest "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 80/tcp my_nginx_1.5.vwzjgeiejvxkki3gaekdumqqj fdefa821b4bc nginx:latest "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 80/tcp my_nginx_1.3.x9m2e4gfrrs517wkde5kb7f9f shell> |
* 각 노드에 분산되어 --replicas 옵션에 설정된 값만큼 컨테이너 생성
예) global 옵션(2개의 노드로 이루어진 swarm 에 1개의 노드 추가)
1) node1(manager 노드)에서 service 생성
shell> docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION tabzxnado7x2fon7x67vqg7m1 node2 Ready Active Leader 19.03.5 qz09j7g6d6mxenvaiu35p616w * node1 Ready Active Reachable 19.03.5 shell> docker service create --mode global --name my_nginx_1 -p 8080:80 nginx:latest czn3k00r2e5u18zfxp6onppd2 overall progress: 2 out of 2 tasks tabzxnado7x2: running qz09j7g6d6mx: running verify: Service converged shell> docker service ls ID NAME MODE REPLICAS IMAGE PORTS czn3k00r2e5u my_nginx_1 global 2/2 nginx:latest *:8080->80/tcp shell> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b53b4ba7ebd0 nginx:latest "nginx -g 'daemon of…" 21 minutes ago Up 21 minutes 80/tcp my_nginx_1.qz09j7g6d6mxenvaiu35p616w.q8sgc8d2afnro563dbqkzz055 shell> |
2) node2 에서 생성된 컨테이너 확인
shell> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf78dff1b293 nginx:latest "nginx -g 'daemon of…" 17 minutes ago Up 17 minutes 80/tcp my_nginx_1.sk2c2wi0p2bqtqjfo8pbom5gf.wvax45gz79c7b7k3zqu1ax0jf shell> |
3) node3에서 swarm에 조인
shell> docker ps => 현재 생성된 컨테이너가 없음 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES shell> docker swarm join --token SWMTKN-1-11a6xx0tp9ikxdzfponlfinetsydfjmncvo9x3zx23in2n9lxh-5puxp1z3p2hss4kimdhuviqi5 192.168.0.167:2377 => manager 노드에서 "docker swarm join-token manager" 명령어로 swarm join 명령어 확인 This node joined a swarm as a manager. shell> docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION tabzxnado7x2fon7x67vqg7m1 node2 Ready Active Leader 19.03.5 sk2c2wi0p2bqtqjfo8pbom5gf * node3 Ready Active Reachable 19.03.5 qz09j7g6d6mxenvaiu35p616w node1 Ready Active Reachable 19.03.5 shell> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bf78dff1b293 nginx:latest "nginx -g 'daemon of…" 11 seconds ago Up 6 seconds 80/tcp my_nginx_1.sk2c2wi0p2bqtqjfo8pbom5gf.wvax45gz79c7b7k3zqu1ax0jf shell> docker service ls ID NAME MODE REPLICAS IMAGE PORTS czn3k00r2e5u my_nginx_1 global 3/3 nginx:latest *:8080->80/tcp shell> |
반응형
'가상화 > Kubernetes' 카테고리의 다른 글
[kubernetes] 설치 (0) | 2020.03.15 |
---|---|
[Docker] swarm 모드에서 컨테이너 rebalance (0) | 2020.01.15 |
[Docker] Volume 관리 (0) | 2020.01.14 |
[Docker] swarm 모드에서 NFS 구성 (0) | 2020.01.10 |
[Docker] Swarm 모드 구성 (0) | 2020.01.09 |