swarm mode
docker-compose
swarm mode + docker-compose ⇒ docker stack
HA Proxy를 통해 접근 할 수 있도록 할 예정
manager에 들어오면 worker로 넘겨주도록
ingress는 HA Proxy만 연결한다. (외부에는 HA Proxy만 접근 할 수 있도록)
attachable로 하면 특정 노드에만 동작하게 되는 것임(이동하지 않고)
rapa@manager:~/0825$ docker network create --driver=overlay --attachable web
c7vic87moqo8ciy1gmltz4qud
rapa@manager:~/0825$ docker network ls
NETWORK ID NAME DRIVER SCOPE
1cf13e62e4aa bridge bridge local
7fccabc7204a docker_gwbridge bridge local
3ead376f089f host host local
iq8afj4dexmr ingress overlay swarm
39430d1f4412 none null local
c7vic87moqo8 web overlay swarm
rapa@manager:~/0825$ touch web.yml
version: '3.7'
services:
nginx:
image: nginx
deploy:
replicas: 3
placement:
constraints: [node.role==worker]
restart_policy:
condition: on-failure
max_attempts: 2
environment:
SERVICE_PORTS: 80
networks: # nginx에서는 외부와 연결하지 않기 때문에 web 네트워크만 연결한다.
- web
proxy:
image: dockercloud/haproxy
depends_on: # web컨테이너를 먼저 만들고 그 ip와 정보들을 도커엔진에 등록해야 하기 때문에 nignx부터 실행하여야 한다.
- nginx
volumes: # nginx에서 왔다갔다 하는 정보들을 proxy에서 보기 위해 volume 적용
- /var/run/docker.sock:/var/run/docker.sock
# proxy에서는 ingress와 web 네트워크 둘다 연결한다.(ports-ingress, networks-web)
ports: # -p option, attached to ingress network
- "80:80"
networks: # backend network -> nginx containers connect
- web
deploy:
mode: global
placement:
constraints: [node.role==manager]
networks:
web:
external: true
rapa@manager:~/0825$ docker stack deploy -c web.yml web
Creating service web_nginx
Creating service web_proxy
web.yml로 배포하기, stack이름은 web이므로 web_nginx, web_proxy 이렇게 생성됨
rapa@manager:~/0825$ docker stack ls
NAME SERVICES ORCHESTRATOR
web 2 Swarm
rapa@manager:~/0825$ docker stack ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
yrdin0n14957 web_nginx.1 nginx:latest worker1 Running Running 3 seconds ago
jdr1g6ddoaot web_nginx.2 nginx:latest worker3 Running Running 2 seconds ago
9sqyp1k2pc4j web_nginx.3 nginx:latest worker2 Running Running less than a second ago
s74t26pg16n7 web_proxy.mmq3j418myp0x5pktz3o0k1jt dockercloud/haproxy:latest manager Running Running 6 seconds ago
proxy는 manager에 배치 되어 있고, nginx는 worker들에 배치되어 있는 것을 확인 가능
에서 컨테이너 정보 등을 확인 할 수 있다.
HA Proxy는 manager에 배치
라벨부착
worker1 → zone = seoul
worker2 → zone = seoul
worker3 → zone = busan
새로운 overlay network : myovl → 서브넷 : 10.10.123.0/24
HA proxy는 자신의 80번 포트를 호스트의 8001과 연결하고, 해당 연결은 myovlnet을 통해 zone=seoul에 배포된 wordpress로 연결된다.
portainer (manager노드에서) worker1,2 모니터링
manager에서 portainer로 모니터링
[관리용 포테이너 설치 @ manager ]
docker container run -d --restart always -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock --name portainer portainer/portainer
docker network create --subnet 10.10.123.0/24 -d overlay --attachable myovlnet
docker node update --label-add zone=seoul worker1
docker node update --label-add zone=seoul worker2
docker node update --label-add zone=busan worker3
touch webquiz.yml
version: '3.7'
services:
wordpress:
image: wordpress
deploy:
replicas: 2
placement:
constraints: [node.labels.zone==seoul]
restart_policy:
condition: on-failure max_attempts: 2
environment:
SERVICE_PORTS: 80
networks:
- myovlnet
proxy:
image: dockercloud/haproxy
depends_on:
- wordpress
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "8001:80"
networks: # backend network -> nginx containers connect
- myovlnet
deploy:
mode: global
placement:
constraints: [node.role==manager]
networks:
myovl
external: true
docker stack deploy -c webquiz.yml webquiz
worker1 | worker2 | worker3 |
---|---|---|
region=seoul | region=seoul | region=jeju |
customer=lg | customer=kia | customer=lg |
ex) ap-northeast-2 : region
ap-northeast-2a : zone
ap-northeast-2b : zone
docker node inspect worker1 --pretty
rapa@manager:~$ docker node update --label-rm zone worker1
worker1
rapa@manager:~$ docker node update --label-rm zone worker2
worker2
rapa@manager:~$ docker node update --label-rm zone worker3
worker3
rapa@manager:~$ docker node update --label-rm company worker1
worker1
rapa@manager:~$ docker node update --label-rm company worker2
worker2
rapa@manager:~$ docker node update --label-rm company worker3
key company doesn't exist in node's labels
rapa@manager:~$ docker node update --label-add region=seoul worker1
worker1
rapa@manager:~$ docker node update --label-add region=seoul worker2
worker2
rapa@manager:~$ docker node update --label-add region=jeju worker3
worker3
rapa@manager:~$ docker node update --label-add customer=lg worker1
worker1
rapa@manager:~$ docker node update --label-add customer=kia worker2
worker2
rapa@manager:~$ docker node update --label-add customer=lg worker3
worker3
version: '3.7'
services:
nginx:
image: nginx
deploy:
replicas: 3
placement: # "-" AND "-"
constraints:
- node.labels.region==seoul
- node.labels.customer==lg
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
rapa@manager:~/0826$ docker stack deploy -c testweb.yml testweb
Updating service testweb_nginx (id: 1evyh4nouqz4rqyh41sg251vk)
Creating service testweb_proxy
namespace : 각각 조건 나눌 수 있는 공간
rapa@manager:~/0826$ docker service inspect testweb_nginx --pretty
ID: 1evyh4nouqz4rqyh41sg251vk
Name: testweb_nginx
Labels:
com.docker.stack.image=nginx
com.docker.stack.namespace=testweb
...