🌱 Infra/Container_Docker Swarm

[docker-swarm (1)] 도컀 μŠ€μ›œ ꡬ성, 맛보기!

mini_world 2020. 10. 26. 15:34
λͺ©μ°¨ μ ‘κΈ°

 

도컀 μŠ€μ›œμ€ λ³„λ„λ‘œ μ„€μΉ˜ν•  ν•„μš” 없이, 도컀 μ„œλ²„ μžμ²΄λ§Œλ“œλ‘œ 도컀 μŠ€μ›œ ν΄λŸ¬μŠ€ν„°λ₯Ό μ†μ‰½κ²Œ ꡬ성할 수 μžˆμŠ΅λ‹ˆλ‹€ ;)
도컀 μŠ€μ›œλͺ¨λ“œλ₯Ό μ œκ³΅ν•˜λŠ”μ§€ ν™•μΈν•˜κΈ° μœ„ν•΄μ„œλŠ” Docker Version을 ν™•μΈν•˜μ—¬ 1.12버전 이상인지 ν™•μΈν•©λ‹ˆλ‹€. 


 

이번 μ‹€μŠ΅μ—μ„œλŠ” Docker Swarm ν΄λŸ¬μŠ€ν„°λ₯Ό κ΅¬μ„±ν•˜κ³  μ‚¬μš©ν•˜λŠ” μ‹€μŠ΅μ„ μ§„ν–‰ν•©λ‹ˆλ‹€. 😁

도컀 μŠ€μ›œμ€, 도컀 μ»¨ν…Œμ΄λ„ˆμ˜ μ˜€μΌ€μŠ€νŠΈλ ˆμ΄μ…˜ 툴이라고 λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€.

https://docs.docker.com/engine/swarm/how-swarm-mode-works/nodes/

도컀 μŠ€μ›œμ€ λ§ˆμŠ€ν„° λ…Έλ“œμ™€ μ›Œμ»€λ…Έλ“œ μ΄λ ‡κ²Œ 2개의 역할이 있으며, λ§€λ‹ˆμ € μ—­ν• μ˜ λ…Έλ“œλŠ” λ°˜λ“œμ‹œ 1개 이상, μ›Œμ»€λ…Έλ“œλŠ” 없을 수 μžˆμŠ΅λ‹ˆλ‹€.
λ§€λ‹ˆμ € 역할을 ν•˜λŠ” λ…Έλ“œλŠ” μ›Œμ»€λ…Έλ“œμ˜ 역할도 μˆ˜ν–‰ν•˜κΈ°λ•Œλ¬Έμž…λ‹ˆλ‹€.

μœ„ 그림은 3개의 Manager λ…Έλ“œμ™€, 7λŒ€μ˜ Worker λ…Έλ“œλ‘œ κ΅¬μ„±λ˜μ–΄μžˆμ§€λ§Œ, 이번 μ‹€μŠ΅μ—μ„œλŠ” 1개의 Manager λ…Έλ“œ, 2개의 Worker λ…Έλ“œλ‘œ κ΅¬μ„±ν•˜μ—¬ μ‹€μŠ΅μ„ μ§„ν–‰ν•˜κ² μŠ΅λ‹ˆλ‹€.

μ‹€ μ‚¬μš©ν™˜κ²½μ—μ„œλŠ” λ°˜λ“œμ‹œ 3κ°œμ΄μƒμ˜ Manager λ…Έλ“œλ₯Ό μ„€μ •ν•΄μ£Όμ„Έμš” :)

μ‹€μŠ΅μ€ μ•„λž˜μ˜ μˆœμ„œλ‘œ μ§„ν–‰λ©λ‹ˆλ‹€.

  • Docker Swarm - Mamager λ…Έλ“œ μ„€μ •
  • Docker Swarm - Worker #1, #2 λ…Έλ“œ μΆ”κ°€
  • Docker Swarm - μ„œλΉ„μŠ€ μ‹œμž‘ν•΄λ³΄κΈ° 

 


 

Docker Swarm μ‹€μŠ΅ ꡬ성

이 κ·Έλ¦Όκ³Ό 같이 총 3개의 μ„œλ²„ μžμ›μ„ μ‚¬μš©ν•˜μ—¬, 1κ°œλŠ” Manager, 2κ°œλŠ” Worker둜 ꡬ성해보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€.
이 μ‹€μŠ΅μ˜ 사전 쑰건은 λ°˜λ“œμ‹œ 1.12μ΄μƒμ˜ 도컀 데λͺ¬μ΄ μ„€μΉ˜λ˜μ–΄μžˆλŠ”κ²ƒμž…λ‹ˆλ‹€.
도컀 μ„€μΉ˜κ°€ λ˜μ–΄μžˆμ§€ μ•Šλ‹€λ©΄ μ—¬κΈ°λ₯Ό ν΄λ¦­ν•˜μ—¬ μ„€μΉ˜λΆ€ν„° ν•©λ‹ˆλ‹€ :)

Docker Swarm - Mamager λ…Έλ“œ μ„€μ •

λ¨Όμ €, Manager λ…Έλ“œμ—μ„œ Swarm init을 μ‹€ν–‰ν•©λ‹ˆλ‹€. 

[root@swarm-manager /]# docker swarm init
Swarm initialized: current node (nimv87d2pupej2uxxzthkugvx) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-23oim81yk3k1pd0ykpz4ezdnh22warxvrjaddtzjvdoqohu5zo-0nd5a0gpav8zp2rkbn45q00oq 172.31.13.191:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

자! 이제 ꡬ성이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€!!! μ΄λ ‡κ²Œ κ°„λ‹¨ν•˜κ²Œ ꡬ성이 λλ‚¬μŠ΅λ‹ˆλ‹€!!! πŸ₯³πŸ₯³
λ§Œμ•½ Manager λ…ΈνŠΈμ— λ„€νŠΈμ›Œν¬ μΈν„°νŽ˜μ΄μŠ€κ°€ μ—¬λŸ¬κ°œ μ‘΄μž¬ν•œλ‹€λ©΄, 
μ–΄λ–€ IPλ₯Ό 쓸것인지 μ •ν•œ 후에 "docker swarm init --advertise-addr <Manager Node IP>" λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•˜λ©΄ λ©λ‹ˆλ‹€.

Docker Swarm - Worker #1, #2 λ…Έλ“œ μΆ”κ°€

Manager λ…Έλ“œλ₯Ό μΆ”κ°€ν• λ•Œ 좜λ ₯됐던 λ‚΄μš©μ€‘μ— "docker swarm join~~" 뢀뢄을 λ³΅μ‚¬ν•˜μ—¬ Worker Node에 λΆ™μ—¬λ„£κΈ° ν•©λ‹ˆλ‹€!

λ¨Όμ €, Worker #1 λ…Έλ“œμ—μ„œ μ§„ν–‰ν•©λ‹ˆλ‹€.

[root@swarm-worker1 /]# docker swarm join --token SWMTKN-1-23oim81yk3k1pd0ykpz4ezdnh22warxvrjaddtzjvdoqohu5zo-0nd5a0gpav8zp2rkbn45q00oq 172.31.13.191:2377
This node joined a swarm as a worker.

이제, λ‘λ²ˆμ§Έλ‘œ Worker #2 λ…Έλ“œμ—μ„œ μ§„ν–‰ν•©λ‹ˆλ‹€.

[root@swarm-worker2 /]# docker swarm join --token SWMTKN-1-23oim81yk3k1pd0ykpz4ezdnh22warxvrjaddtzjvdoqohu5zo-0nd5a0gpav8zp2rkbn45q00oq 172.31.13.191:2377
This node joined a swarm as a worker.

 

μ΄λ ‡κ²Œ λ‘κ°œμ˜ λ…Έλ“œκ°€ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 3개의 λ…Έλ“œ λͺ¨λ‘ 잘 μš΄μ˜μ€‘μΈμ§€ ν™•μΈν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.

[root@swarm-manager /]# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
nimv87d2pupej2uxxzthkugvx *   swarm-manager       Ready               Active              Leader              19.03.13
c60u9g03hg4z1co9a6pitimmo     swarm-worker1       Ready               Active                                  19.03.13
r7vk73m3yi3nm0p3k11xfmf5e     swarm-worker2       Ready               Active                                  19.03.13

λͺ¨λ‘ Active μƒνƒœλ‘œ 잘 μš΄μ˜μ€‘μ΄λ„€μš”.
μ—¬κΈ°μ—μ„œ λ³„ν‘œ(*)κ°€ 뢙은 λ…Έλ“œκ°€ ν˜„μž¬ λ…Έλ“œμž…λ‹ˆλ‹€.

μΆ”κ°€μ μœΌλ‘œ :)
μƒˆλ‘œμš΄ λ§€λ‹ˆμ € λ…Έλ“œλ₯Ό μΆ”κ°€ν•˜κ±°λ‚˜, μƒˆλ‘œμš΄ μ›Œμ»€ λ…Έλ“œλ₯Ό μΆ”κ°€ν• λ•ŒλŠ” μ•„λž˜μ™€ 같은 λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

<!-- Manager Node μΆ”κ°€ -->
[root@swarm-manager /]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-23oim81yk3k1pd0ykpz4ezdnh22warxvrjaddtzjvdoqohu5zo-bw42g26eho9dohi1nl2og0ur5 172.31.13.191:2377

<!-- Worker Node μΆ”κ°€ -->
[root@swarm-manager /]# docker swarm join-token worker
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-23oim81yk3k1pd0ykpz4ezdnh22warxvrjaddtzjvdoqohu5zo-0nd5a0gpav8zp2rkbn45q00oq 172.31.13.191:2377
    

 

Docker Swarm - μ„œλΉ„μŠ€ μ‹œμž‘ν•΄λ³΄κΈ° 

이번 λ‹¨κ³„μ—μ„œλŠ” 도컀 μŠ€μ›œμ—μ„œ λ§›λ³΄κΈ°λ‘œ μ„œλΉ„μŠ€λ₯Ό μ‹œμž‘ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€ :)

Docker Service λͺ…λ Ήμ–΄λ₯Ό μ΄μš©ν•΄μ„œ μ„œλΉ„μŠ€λ₯Ό μƒμ„±ν•˜κ² μŠ΅λ‹ˆλ‹€.

[root@swarm-manager /]# docker service create --replicas 5 --name helloworld alpine ping docker.com
q6vjfrr3q7mqbwwb6ea7evfxc
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

μ„œλΉ„μŠ€ 생성이 μ™„λ£Œ λ˜μ—ˆλŠ”μ§€ ν™•μΈν•˜κ² μŠ΅λ‹ˆλ‹€.  확인 λͺ…λ Ήμ–΄λŠ” docker service ls (μ„œλΉ„μŠ€ λͺ©λ‘ 확인), docker service ps <μ„œλ―ΈμŠ€λͺ…> (μ„œλΉ„μŠ€ λ‚΄ μ»¨ν…Œμ΄λ„ˆ μƒνƒœ 확인) μž…λ‹ˆλ‹€!

<!-- 도컀 μ„œλΉ„μŠ€ λͺ©λ‘ 확인 -->
[root@swarm-manager /]# docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
q6vjfrr3q7mq        helloworld          replicated          5/5                 alpine:latest       

<!-- 도컀 μ„œλΉ„μŠ€μ˜ μ»¨ν…Œμ΄λ„ˆ μƒνƒœ 확인 -->
[root@swarm-manager /]# docker service ps helloworld
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE                ERROR               PORTS
rqxf9vw6mwcj        helloworld.1        alpine:latest       swarm-worker1       Running             Running about a minute ago                       
ds9rj06j94f3        helloworld.2        alpine:latest       swarm-worker2       Running             Running about a minute ago                       
jrvq3yuq4wxk        helloworld.3        alpine:latest       swarm-manager       Running             Running about a minute ago                       
nqpnq5ewrdch        helloworld.4        alpine:latest       swarm-worker1       Running             Running about a minute ago                       
z904et43297e        helloworld.5        alpine:latest       swarm-manager       Running             Running about a minute ago      

 

자! μ—¬κΈ°κΉŒμ§€ λ§›λ³΄κΈ°μ˜€μŠ΅λ‹ˆλ‹€!!

λ‹€μŒ μŠ€νƒ­μœΌλ‘œ κ°‘μ‹œλ‹€ !!

728x90