[Docker] Docker swarm ์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜

Docker swarm

  • docker swarm์€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์œ„ํ•œ ๋ถ„์‚ฐ ํ™˜๊ฒฝ ํด๋Ÿฌ์Šคํ„ฐ๋ง ๋ฐ ์Šค์ผ€์ค„๋ง ๋„๊ตฌ์ด๋‹ค.
  • Docker๋Š” ๋‹จ์ผ ํ˜ธ์ŠคํŠธ, Docker swarm์€ ๋‹ค์ค‘ ํ˜ธ์ŠคํŠธ ๊ธฐ๋ฐ˜์˜ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ด€๋ฆฌ ๋„๊ตฌ์ด๋‹ค.
  • "์ปจํ…Œ์ด๋„ˆํ™” ๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์ž๋™ํ™”๋œ ๊ด€๋ฆฌ ๋ฐ ์ œ์–ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๋„๊ตฌ"
  • swarm mode๋ฅผ ์ดˆ๊ธฐํ™”(init)ํ•˜์—ฌ ์‚ฌ์šฉ

 

 

 

์ฃผ์š” ๊ธฐ๋Šฅ

  • DNS ์„œ๋ฒ„๋ฅผ ํ†ตํ•ด ์„œ๋น„์Šค ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๊ฐ€๋Šฅ
  • ์„œ๋น„์Šค์šฉ ํฌํŠธ๋ฅผ ์™ธ๋ถ€ Load Balancer์— ์—ฐ๊ฒฐํ•˜์—ฌ ๋ถ€ํ•˜ ๋ถ„์‚ฐ ๊ตฌํ˜„
  • ๊ฐ ๋…ธ๋“œ๋Š” TLS(Transport Layer Security) ์ƒํ˜ธ ์ธ์ฆ ๋ฐ ์•”ํ˜ธํ™”๋ฅผ ํ†ตํ•ด ๋…ธ๋“œ ๊ฐ„ ํ†ต์‹ ์— ๋Œ€ํ•œ ๋ณด์•ˆ ๊ธฐ๋Šฅ ๊ตฌํ˜„
  • Docker์—”์ง„๊ณผ ํ†ตํ•ฉ๋œ multi host๊ธฐ๋ฐ˜์˜ ๋ถ„์‚ฐ Cluster ์šด์˜
  • ์„œ๋น„์Šค์— ๋Œ€ํ•œ ๋ฉ€ํ‹ฐ ํ˜ธ์ŠคํŠธ ํด๋Ÿฌ์Šคํ„ฐ ๋„คํŠธ์›Œํฌ(overlay) ์‚ฌ์šฉ์œผ๋กœ overlay network์˜ ์ปจํ…Œ์ด๋„ˆ ์ฃผ์†Œ ์ž๋™ ํ• ๋‹น. (๊ธฐ์กด์—๋Š” bridge network๋งŒ ์‚ฌ์šฉ)

 

 

 

Docker swarm mode ์ฃผ์š” ์šฉ์–ด ์ •๋ฆฌ

Node

Docker swarm cluster๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ฐ๊ฐ์˜ Docker host

Manager Node  |  Worker Node

Cluster ๊ด€๋ฆฌ ๋ฐ ์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜์„ ๋‹ด๋‹นํ•˜๋Š” ๋…ธ๋“œ  |  ์„œ๋น„์Šค๋“ค์ด ์‹ค์ œ ๋™์ž‘ํ•˜๋Š” ๋…ธํŠธ

Stack

๋‹ค์ค‘ ์ปจํ…Œ์ด๋„ˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋™์ž‘์‹œํ‚ค๋Š” ์„œ๋น„์Šค ๋ฌถ์Œ

Service

Node์—์„œ ์ˆ˜ํ–‰ํ•˜๊ณ ์ž ํ•˜๋Š” ์ž‘์—…(๋ฐฐํฌ) ๋‹จ์œ„

Task

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋™์ž‘ํ•  ์ปจํ…Œ์ด๋„ˆ. 

ํ•˜๋‚˜์˜ Service๋Š” replica ์ˆ˜์— ๋”ฐ๋ผ ์—ฌ๋Ÿฌ ๊ฐœ์˜ Task ๋ณด์œ , ๊ฐ Task์—๋Š” ํ•˜๋‚˜์˜ ์ปจํ…Œ์ด๋„ˆ ํฌํ•จ.

Scheduling

Service ๋ช…์„ธ์— ๋”ฐ๋ผ Task (์ปจํ…Œ์ด๋„ˆ)๋ฅผ node์— ๋ถ„๋ฐฐํ•˜๋Š” ์ž‘์—…

 

 

์š”์ฒญ -> Ingress -> Ingress ์˜ IPVS -> service ์ฐพ์Œ -> task์˜ IP๋ฅผ ํ™•์ธ -> ์—ฐ๊ฒฐ

 

์‹ค์Šต์œผ๋กœ ๋„˜์–ด๊ฐ€๋ณด์ž

  • docker swarm mode๋กœ ์ดˆ๊ธฐํ™”ํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด Swarm: inactive์ธ ์ƒํƒœ์ผ ๊ฒƒ์ด๋‹ค.
$ docker info | grep Swarm
Swarm: inactive

 

  • init์„ ํ†ตํ•ด magager node์—์„œ swarm cluster๋ฅผ ์‹œ์ž‘
  • --advertise-addr์€ ๋‹ค๋ฅธ swarm node๋“ค์ด manager node์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•œ IP ์ž…๋ ฅ.
  • docker swam join --~~~~~ ์ด ๋ถ€๋ถ„์„ ๋‹ค๋ฅธ host๋“ค์— ์ž…๋ ฅํ•ด์ค˜์•ผ Manager Node์™€ Worker Node๊ฐ„ ์—ฐ๊ฒฐ์ด ๋œ๋‹ค.
$ docker swarm init --advertise-addr 192.168.56.101 
Swarm initialized: current node (vlrxjintax2ocbeordx1kkqa4) is now a manager.
To add a worker to this swarm, run the following command: 
docker swarm join --token SWMTKN-1-65xez391hlozgvo23dazr4suxca5kp4qfvklzs2ch2zl3m79iv9z5rkc5waujalxonpqi46booc 192.168.56.201:2377

 

  • docker swarm ํ™•์ธ์€ portainer.io์—์„œ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์–ด๋–ค Node๋“ค์ด ์žˆ๋Š”์ง€ ํ™•์ธ ๊ฐ€๋Šฅ
  • ํ˜„์žฌ ์˜ฌ๋ผ๊ฐ€์žˆ๋Š” stack, service๋“ฑ์— ๋Œ€ํ•ด์„œ ํ™•์ธ ๊ฐ€๋Šฅ

  • ์ง๊ด€์ ์œผ๋กœ docker swarm์„ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๊ณ ์‹ถ๋‹ค๋ฉด visualizer์„ ์„ค์น˜ํ•ด์ฃผ๋ฉด๋œ๋‹ค.
  • swarm ์ „์šฉ ๋ชจ๋‹ˆํ„ฐ๋ง ํˆด
  • ์„œ๋น„์Šค๊ฐ€ ์˜ฌ๋ผ์˜ฌ ๋•Œ ์–ด๋””์— ์˜ฌ๋ผ์˜ค๋Š”์ง€ ์ง๊ด€์ ์œผ๋กœ ํ™•์ธ ๊ฐ€๋Šฅ
$ docker service create \
> --name=viz_swarm \ 
> --publish=8082:8080 \ 
> --constraint=node.role==manager \
> --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \ 
> dockersamples/visualizer

 

  • docker swarm nginx ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ด๋ณด์ž

$ docker service create --name myweb --replicas=3 -p 8001:80 nginx:1.25.0-alpine //์„œ๋น„์Šค ์ƒ์„ฑ
$ docker service ls //
$ docker service ps myweb // ์–ด๋”” Node์—์„œ ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰์ค‘์ธ์ง€ ๋ณผ ์ˆ˜ ์žˆ์Œ

 

 

 

Docker stack ํ™œ์šฉ (feat.Docker compose)

docker compose์™€๋Š” ๋ญ๊ฐ€ ๋‹ค๋ฅผ๊นŒ?

  • docker swarm์€ ์—ฌ๋Ÿฌ ๋…ธ๋“œ๋กœ ๊ตฌ์„ฑ๋œ ํด๋Ÿฌ์Šคํ„ฐ ํ™˜๊ฒฝ์—์„œ ์„œ๋น„์Šค๋ฅผ ํ†ตํ•ด ์ปจํ…Œ์ด๋„ˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•œ๋‹ค.
  • docker compose๋Š” ์ปจํ…Œ์ด๋„ˆ ๊ฐ„์˜ ์—ฐ๊ฒฐ์„ฑ์„ ์ œ๊ณตํ•˜์ง€๋งŒ, ๋™์ผ ํ˜ธ์ŠคํŠธ์—์„œ ์‹คํ–‰๋˜๋ฏ€๋กœ ์ˆ˜ํ‰ ํ™•์žฅ์€ ํ•œ ํ˜ธ์ŠคํŠธ์˜ ๋ฆฌ์†Œ์Šค๋กœ ์ œํ•œ๋œ๋‹ค.
  • docker stack์€ docker swarm, docker compose ๋‘ ๊ธฐ์ˆ ์„ ์—ฐ๊ฒฐํ•˜๊ณ  yaml์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ swarm์— ์—ฐ๊ฒฐ๋œ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๋…ธ๋“œ์— ์—ฐ๊ฒฐ๋œ ์ปจํ…Œ์ด๋„ˆ ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์—ฐ๊ฒฐ์„ฑ์„ ์ œ๊ณต