[DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Ansible + Kubernetes ์™€์˜ ์—ฐ๋™

2022. 9. 7. 22:12ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

์ด ๋‚ด์šฉ์€ ์ธํ”„๋Ÿฐ - Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ ์ž…๋‹ˆ๋‹ค.


ํ•ด๋‹น ๋‚ด์šฉ์˜ Code ๋‚ด์šฉ์€ ์ด ๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



 

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์™„๋ฒฝ ๊ฐ€์ด๋“œ:์ž…๋ฌธ๋ถ€ํ„ฐ ์‹ค์ œ ์šด์šฉ๊นŒ์ง€ ํ•„์š”ํ•œ ๊ธฐ์ˆ  ์ด๋ง๋ผ!

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 




๐Ÿ—‚ ๋ชฉ์ฐจ

โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ž๋™ํ™” ๋„๊ตฌ์˜ ์‚ฌ์šฉ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Infrastructure as Code ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Ansible + Kubernetes ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘  - Pipeline
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ก - SonarQube
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ข - Multi Nodes
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ƒ์šฉ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๊ธฐ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ๋ถ€๋ก


 






 

๐Ÿš€ Jenkins, Ansible, Kubernetes ์—ฐ๋™

    ๐Ÿ”ฝ  ๊ฐœ์š”

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๊ณต์‹ ์ž๋ฃŒ

์ „ํ†ต์ ์ธ ๋ฐฉ๋ฒ• ์ฆ‰, ์˜จํ”„๋ ˆ๋ฏธ์Šค ๊ธฐ๋ฐ˜์—์„œ ๋ฐฐํฌ๋ฅผ ํ•œ๋‹ค๋Š” ๊ฒƒ์€ ๋ฌผ๋ฆฌ์  Hardware์— OS(์šด์˜์ฒด์ œ)๋ฅผ ์˜ฌ๋ฆฌ๊ณ , ๊ทธ ์œ„์— Application์„ ์˜ฌ๋ ค ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด์˜€์–ด์š”.

ํ•˜๋‚˜์˜ Application์ด ์ž์›์„ ๋งŽ์ด ์ฐจ์ง€ํ•˜๊ฒŒ ๋˜๋ฉด ๋‹ค๋ฅธ Application์€ ์ž์›์„ ์“ฐ์ง€ ๋ชปํ•ด ์„ฑ๋Šฅ์ด ๋–จ์–ด์ง€๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์–ด์š”.

์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์—ฌ๋Ÿฌ๋Œ€์˜ ๋ฌผ๋ฆฌ ๋จธ์‹ ์„ ๋‘๊ณ , Application์„ ๊ฐ๊ฐ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ์‹์„ ์“ฐ๊ธฐ๋„ ํ–ˆ์—ˆ๋Š”๋ฐ, ๋น„์šฉ์˜ ๋ฌธ์ œ์™€ ์ž์›์˜ ํ™•์žฅ ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์–ด์š”.


๋‘๋ฒˆ์งธ๋Š” ๊ฐ€์ƒํ™” ์†”๋ฃจ์…˜์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์–ด์š”.
๋Œ€ํ‘œ์ ์œผ๋กœ VM Ware์‚ฌ์˜ exsi๋‚˜, Windows์˜ Hyper-V ๋“ฑ์ด ์žˆ์–ด์š”.

๊ฐ€์ƒํ™”์˜ ๊ฒฝ์šฐ ๋ฌผ๋ฆฌ ๋จธ์‹ ์œ„์— ๊ฐ€์ƒํ™” OS๋ฅผ ์˜ฌ๋ฆฌ๊ณ , ๊ทธ ์œ„์— Hypervisor๊ฐ€ ์˜ฌ๋ผ๊ฐ€๊ฒŒ ๋˜๋Š”๋ฐ, ์ด ๊ธฐ์ˆ ์„ ํ†ตํ•ด ๊ฐ๊ฐ์˜ VM(๊ฐ€์ƒ ๋จธ์‹ )์— ๊ฐœ๋ณ„ OS๋ฅผ ์˜ฌ๋ฆฌ๊ณ , Application์„ ์šด์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ํ•œ ๋ฌผ๋ฆฌ ๋จธ์‹ ๋‚ด์— ์—ฌ๋Ÿฌ ๊ฐ€์ƒ ๋จธ์‹ ์€ ๊ฐ๊ฐ์˜ ๋…๋ฆฝ ์ž์›์„ ๊ฐ–์„ ์ˆ˜ ์žˆ๊ฒŒ ๋จ์œผ๋กœ ๊ฐ๊ฐ์˜ Application๋“ค์ด ์‚ฌ์šฉํ•˜๋Š” ์ž์›์„ ํ†ต์ œํ•  ์ˆ˜ ์žˆ๊ณ , ์ƒํ˜ธ ๋ณด์•ˆ๋„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ์–ด์š”.

ํ•˜์ง€๋งŒ, ๊ฐ€์ƒํ™”์˜ ๊ฒฝ์šฐ ๋ฌผ๋ฆฌ ์„œ๋ฒ„๋‚ด์— ์—ฌ๋Ÿฌ ๊ฐ€์ƒ ๋จธ์‹ ์ด ์˜ฌ๋ผ๊ฐ€๊ฒŒ ๋˜๋ฉด ์ž์›์€ ์ค„๊ฒŒ ๋˜๊ณ , ๋ถ€ํ•˜๊ฐ€ ์ปค์ง€๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”.


์„ธ๋ฒˆ์งธ๋กœ Container ๊ฐ€์ƒํ™” ๋ฐฉ๋ฒ•์ด ์žˆ์–ด์š”.
์ด ๋ฐฉ๋ฒ•์€ VM๊ณผ ์œ ์‚ฌํ•œ ๋ฐฉ๋ฒ•์ธ๋ฐ, ๊ฐ ๊ฐ€์ƒ ๋จธ์‹ ์— ๋Œ€ํ•ด ๊ฒฉ๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„์„ ์ข€ ๋” ์™„ํ™”ํ•ด์„œ Application ๊ฐ„ ์šด์˜์ฒด์ œ๋ฅผ ์„œ๋กœ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด์—์š”.

๋˜ํ•œ Container ๊ฐ€์ƒํ™”๋Š” VM๋ฐฉ์‹๊ณผ ๋‹ค๋ฅด๊ฒŒ ๊ฐ ๊ฐ€์ƒ๋จธ์‹ ์— OS๊ฐ€ ์ถ”๊ฐ€๋กœ ์„ค์น˜๋˜๋Š” ๋ฐฉ์‹์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ข€ ๋” ๊ฐ€๋ณ๊ฒŒ ์šด์˜์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์žฅ์ ์ด ์žˆ์–ด์š”.

๋˜ํ•œ Host Server์˜ ์ž์›์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ๋„ ํ•ด์š”.


CNCF(Cloud Native Interactive Landscape)


Kubernetes(K8s)๋Š” ์˜คํ”ˆ ์†Œ์Šค ๊ธฐ๋ฐ˜์˜ Containerํ™” ๋œ Application(Work load & Service)์˜ ์ž๋™ ๋ฐฐํฌ, ์Šค์ผ€์ผ๋ง ๋“ฑ์„ ์ œ๊ณตํ•˜๋Š” ๊ด€๋ฆฌ Platform์ด์—์š”.

K8s์™€ Docker๋Š” ์—„์—ฐํžˆ ๋‹ค๋ฅธ ์†”๋ฃจ์…˜์ด์—์š”.
K8s์™€ Docker๋Š” ์ƒํ˜ธ ๋Œ€์ฒดํ•  ์ˆ˜ ์—†์–ด์š”.

K8s๋Š” Container ๊ฐ€์ƒํ™” ๊ธฐ์ˆ ์„ ์ด์šฉํ•œ Service, Packaging๋œ Serivce์˜ ์ž๋™ ๋ฐฐํฌ, Scaling ์ž‘์—…์„ ๋„์™€์ฃผ๋Š” ๋„๊ตฌ์—์š”.





K8s์˜ ์žฅ/ ๋‹จ์ 

์žฅ       ์ 

๋‹จ       ์ 

Containerํ™” ๋œ Application ๊ตฌ๋™

Source Code ๋ฐฐํฌ ๋ถˆ๊ฐ€, Build ๋ถˆ๊ฐ€

Service Discovery & Load balancing

Application Level Service ์ง€์› ์—†์Œ

Storage orchestration

Logging, Monitoring Solution ์ง€์› ์—†์Œ

์ž๋™ํ™”๋œ Roll Out, Roll Back

ํฌ๊ด„์  Machine Setting,
์œ ์ง€๋ณด์ˆ˜, ๊ด€๋ฆฌ, ์ž๋™ ๋ณต๊ตฌ ์‹œ์Šคํ…œ ์ œ๊ณต ์—†์Œ

์ž๋™ํ™”๋œ Bin Packing

 

์ž๋™ํ™”๋œ Self-Healing (๋ณต๊ตฌ)

 

Secret & composition Management (๊ตฌ์„ฑ ๊ด€๋ฆฌ)

 





K8s Cluster๋ž€?


K8s๋Š” Master Node(๊ฐ๊ฐ์˜ Work Node ๊ด€๋ฆฌ)์™€ ์‹ค์ œ Container ์ž์ฒด ์šด์˜, ์Šค์ผ€์ฅด๋ง์„ ๋‹ด๋‹นํ•˜๋Š” ๊ฒƒ์ด Work Node์ด๊ณ , ์ด ๋‘๊ฐ€์ง€๋ฅผ ํ•ฉ์ณ์„œ ๋ถ€๋ฅด๋Š” ๊ฒƒ์ด K8s Cluster์—์š”.

Master Node ์•ˆ์—๋Š” ์„ค์ • ์ •๋ณด(etcd), ์‚ฌ์šฉ์ž ์Šค์ผ€์ฅด ๊ด€๋ฆฌ(sched), api ๋“ฑ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌ์„ฑ์ด ๋˜์–ด ์žˆ์–ด์š”.

Work Node ์•ˆ์—๋Š” ์‹ค์ œ๋กœ ์šด์˜ํ•˜๊ณ ์ž ํ•˜๋Š” Container๋“ค์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ pod๋ผ๋Š” ๊ฐœ๋…, ์ด pod๋ฅผ ์šด์˜ํ•˜๊ธฐ ์œ„ํ•œ kubelet์ด๋ผ๋Š” ๊ฐœ๋…์ด ํฌํ•จ๋˜์–ด ์žˆ์–ด์š”.


 
๊ฐœ๋ฐœ์ž๋‚˜, ๊ด€๋ฆฌ์ž๊ฐ€ ๊ฐ๊ฐ์˜ ์ ‘๊ทผ Tool(UI๋ฅผ ๊ฐ€์ง„ Web Service Tool ํ˜น์€ CLI Tool)๋กœ K8s Master Node API์— ๋ช…๋ น์–ด๋ฅผ ์ „๋‹ฌํ•˜๋ฉด API๋Š” ์ž๊ธฐ๊ฐ€ ๊ฐ€์šฉํ•  ์ˆ˜ ์žˆ๋Š” Work Node๋“ค์—๊ฒŒ ๊ฐœ๋ฐœ์ž๋‚˜, ๊ด€๋ฆฌ์ž๊ฐ€ ๋ณด๋‚ธ ๋ช…๋ น์–ด๋ฅผ ์ „๋‹ฌํ•˜๊ฒŒ ๋˜์š”.

API๊ฐ€ ์ „๋‹ฌํ•œ ๋ช…๋ น์–ด๋Š” Cube(K8s) Proxy๊ฐ€ ๋ฐ›๋Š” ์—ญํ• ์„ ํ•˜๋Š”๋ฐ,  Cube(K8s) Proxy๋Š” Cluster์˜ ๊ฐ Work Node์—์„œ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” Network Proxy์—์š”.
์ฆ‰, K8s์—์„œ Service์˜ ๊ฐœ๋…์œผ๋กœ ๋ณด๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„์š”.
์ด ์นœ๊ตฌ๋Š” Network์— ์œ ์ง€, ๊ด€๋ฆฌ๋ฅผ ๋‹ด๋‹นํ•˜๊ณ  ์žˆ์–ด์š”.




Master Node์—์„œ ๊ฐ๊ฐ ๊ฐ€์šฉํ•  ์ˆ˜ ์žˆ๋Š” Work Node์— ์–ด๋–ค ๋ช…๋ น์–ด๋ฅผ ์ „๋‹ฌํ•˜๋ฉด ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ Container๋ฅผ Pod ํ˜•ํƒœ๋กœ ๋ฌถ์–ด์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ธ ํ˜•ํƒœ์—์š”.

K8s๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ์†Œํ•œ์˜ ๋‹จ์œ„์ธ Pod๋ผ๋Š” ํ˜•ํƒœ๋กœ ๋ฌถ์–ด ๋ฐฐํฌ๋ฅผ ํ•˜๊ฒŒ ๋˜๊ณ , ์ด Pod์•ˆ์—๋Š” ์—ฌ๋Ÿฌ Container๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ์–ด์š”.

๊ฐ๊ฐ์˜ Work Node๋Š” Container๋ฅผ ์šด์˜ํ•˜๊ธฐ ์œ„ํ•œ Container Engine์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•ด์š”.

Work Node๋ฅผ ๋‹จ์ผ Node๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์•ˆ์ •์ ์ธ Service๋ฅผ ์œ„ํ•ด Multi Node๋ฅผ ๊ฐ€์ง€๊ณ , K8s Cluster๋ฅผ ๊ตฌ์„ฑํ•˜๋Š”๊ฒŒ ์ข‹์•„์š”.




Pod์•ˆ์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ฆ‰, Work Node์•ˆ์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” Service๋ฅผ ํ™•๋Œ€ํ•ด์„œ ์‚ดํŽด๋ณผ๊ฒŒ์š”.

์ผ๋‹จ, Service์™€ Pod ๊ฐœ๋…์ด ์กด์žฌํ•˜๋Š”๋ฐ, ์ด ๋‘ ์นœ๊ตฌ๋Š” K8s๊ฐ€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” Object ๋˜๋Š” ์ž์›(Resource)๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ๊ฐœ๋…์ด๊ณ , Service๋Š” ๊ฐ๊ฐ์˜ Pod ๊ฐ„์— Data๋ฅผ ์ฃผ๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก Network ๊ด€๋ จ ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์นœ๊ตฌ์—์š”.

Pod๋Š” Container๋“ค์ด Packaging ๋˜์–ด ์žˆ๋Š” ์ตœ์†Œํ•œ์˜ ๋‹จ์œ„์ด๊ณ , Application๋“ค์ด ๋ฌถ์—ฌ ์žˆ๋Š” ๊ฒƒ์ด๋ผ๊ณ  ๋ณด๋ฉด ๋  ๊ฑฐ ๊ฐ™์•„์š”.





 

 

    ๐Ÿ”ฝ  ์„ค์น˜ํ•˜๊ธฐ

        ๐Ÿ“ฆ Kubernetes ์„ค์น˜


Kubernetes ์„ค์น˜ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๊ณณ์— ์ •๋ฆฌ๋ฅผ ํ•ด ๋‘์—ˆ์–ด์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ CentOS7์— ๊ฐ€์ƒํ™” ์†”๋ฃจ์…˜์„ ์˜ฌ๋ฆฌ๊ณ , ๊ทธ ๊ณณ์— 3๊ฐœ์˜ Guest OS (CentOS 7)์„ ์˜ฌ๋ ค Study ํ™˜๊ฒฝ์„ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.






        ๐Ÿ“ฆ Minikube ์„ค์น˜

Minikube๋Š” Test ํ˜น์€ ๊ฐœ๋ฐœ์šฉ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋ฒผ์šด ๋ชฉ์ ์— Kubernetes์—์š”.

Minikube๋ฅผ ํ†ตํ•ด Kubernetes Cluster๋ฅผ ๋ณต์žกํ•˜๊ฒŒ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, Docker Desktop ๋“ฑ์„ ์ด์šฉํ•ด์„œ Sigle Cluster๋กœ ๊ตฌ์ถ•๋œ ์ƒํƒœ์— Kubernetes๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์นœ๊ตฌ์—์š”.


Docker Desktop ์„ค์ •์—์„œ ์œ„์™€ ๊ฐ™์ด Enable Kubernetes๋ฅผ ํ™œ์„ฑํ™” ํ•ด ์ค€ ๋’ค Apply & Restart๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ์„ค์น˜๊ฐ€ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

์œ„์— ๋ฐฉ๋ฒ•์€ Mac, Windows์—์„œ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด๊ณ , ํ˜น์‹œ๋‚˜ CentOS์™€ ๊ฐ™์€ Linux ํ™˜๊ฒฝ์—์„œ ์„ค์น˜๋ฅผ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด ๊ณณ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.



kubectl get nodes

728x90


Docker Desktop์—์„œ Kubernetes ์„ค์ •์ด ์™„๋ฃŒ๋œ ๋’ค ์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์ฃผ๋‹ˆํ•˜๋ž‘ Mac Book์— ์–ด๋–ค Node๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ์„ ํ•ด ๋ณด์•˜์–ด์š”.

์œ„์™€ ๊ฐ™์ด Minikube๋ฅผ ์ด์šฉํ•˜๋ฉด Single Cluster ๋ฐฉ์‹์ด๋ผ๊ณ  ํ•˜์˜€์—ˆ๋Š”๋ฐ, ์ด๋Š” Master์™€ Worcker Node๋ฅผ ํ•œ ๊ณณ์—์„œ ์ด์šฉํ•œ๋‹ค๋Š” ์˜๋ฏธ์—์š”.


์‹ค์ œ ์šด์˜ ํ™˜๊ฒฝ์—์„œ๋Š” ์œ„์™€ ๊ฐ™์ด ํ•˜์ง„ ์•Š์„๊ฑฐ์—์š”.


 

kubectl get pods

kubectl get deployments

kubectl get services


์ตœ์ดˆ pods์— ๋Œ€ํ•œ ๋ช…๋ น์–ด๋Š” ํ˜„์žฌ ๊ธฐ๋™์ค‘์ธ pod ๋ชฉ๋ก์„ ํ™•์ธํ•˜๋Š” ๋ช…๋ น์–ด์—์š”.
์ฃผ๋‹ˆํ•˜๋ž‘์€ ํ˜„์žฌ ๊ธฐ๋™์ค‘์ธ Pod๋‚˜, deployment Object๊ฐ€ ์—†๋Š” ๊ฒƒ์œผ๋กœ ํ™•์ธ์ด ๋˜์—ˆ์–ด์š”.






    ๐Ÿ”ฝ  Kubernetes

        ๐Ÿ“ฆ ๊ธฐ๋ณธ ๋ช…๋ น์–ด


์œ„์™€ ๊ฐ™์ด sample-nginx๋ผ๋Š” ์ด๋ฆ„์„ ๊ฐ€์ง„ ์‚ฌ์šฉํ•  Image๋ฅผ nginx Image๋ฅผ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๊ณ  ํ•œ ๋’ค port๋ฅผ ์„ค์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด pod(Kubernetes ์ตœ์†Œ ๋‹จ์œ„)๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์–ด์š”.


kubectl get pods


Kubernetes์˜ pod๊ฐ€ ํ•˜๋‚˜ ๊ธฐ๋™์ค‘์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

์œ„์— READY์— ์ˆซ์ž๊ฐ€ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์€ ํ•ด๋‹น Pod์•ˆ์— Container ๊ฐœ์ˆ˜ ์ฆ‰, ์ •์ƒ ๊ธฐ๋™์ค‘์ธ Container๊ฐ€ ๋ช‡ ๊ฐœ์ธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์ด์—์š”.

์ผ๋ฐ˜์ ์œผ๋กœ ํ•œ ๊ฐœ์˜ Pod์•ˆ์—๋Š” ํ•˜๋‚˜์˜ Container๋ฅผ ๋„ฃ์–ด์š”.



kubectl describe pods {pod ์ด๋ฆ„}


์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด pod์— ๋Œ€ํ•œ ์ƒ์„ธ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.
ํ•ด๋‹น pod๋Š” ํ˜„์žฌ docker-desktop์ด๋ผ๋Š” Wocker Node์— ์„ค์น˜๊ฐ€ ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

๋˜ํ•œ, Evnets์—๋Š” ์ •์ƒ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


๋งŒ์•ฝ ๋งŒ๋“  pod๋ฅผ ์‚ญ์ œํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋Š” ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด ์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

kubectl delete pod/{pod ์ด๋ฆ„}

 


์œ„์™€ ๊ฐ™์ด pod๊ฐ€ ์ œ๊ฑฐ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


Deployment๋Š” ์šฐ๋ฆฌ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” Pod๋ฅผ ๋ฆฌํ”Œ๋ฆฌ์นด ์„ธํŠธ๋ผ๊ณ  ํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ˜•ํƒœ๋กœ ์Šค์ผ€์ผ ํ•ด์„œ ๋งŒ๋“ค๊ฑฐ๋‚˜, ์Šค์ผ€์ฅด๋ง, ํžˆ์Šคํ† ๋ฆฌ ์ž‘์—…์„ ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์„ค์น˜ ๊ฐœ๋…์ด์—์š”.


kubectl create deployment {์›ํ•˜๋Š” deployment ์ด๋ฆ„} --image={image ์ด๋ฆ„}

๋ฐ˜์‘ํ˜•


์œ„์™€ ๊ฐ™์ด deployment๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์•˜์–ด์š”.

Deployment๋„ pod๋ฅผ ๋ฐฐํฌํ•˜๋Š” ๊ฐœ๋…์ด๋ผ๊ณ  ๋ณด๋ฉด ๋˜๋Š” ๊ฒƒ์ด์—์š”.
Pod์˜ ์ƒ์œ„ ๊ฐœ๋…์œผ๋กœ ๋ฐฐํฌ ๋‹จ์œ„๋ฅผ Deployment ๊ฐ์‹ธ์„œ ๋ฐฐํฌํ•˜๊ฒŒ ๋˜๋ฉด ์Šค์ผ€์ผ๋ง ์ž‘์—…, ์Šค์ผ€์ฅด ์ž‘์—… ๋“ฑ์„ ํ•  ๋•Œ, ํ›จ์”ฌ ํŽธํ•˜๊ฒŒ ์ž‘์—… ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ด์ ์ด ์žˆ๋‹ต๋‹ˆ๋‹ค.


kubectl get deployments


์œ„์™€ ๊ฐ™์ด Deployment๊ฐ€ ์ œ๋Œ€๋กœ ์ƒ์„ฑ์ด ๋œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



kubectl get pods


pod ๋ชฉ๋ก์„ ์กฐํšŒํ•ด ๋ณด๋ฉด ์œ„์™€ ๊ฐ™์ด ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์„ค์ •ํ•œ ์ด๋ฆ„ ๋’ค์— Random ๊ฐ’์ด ์ถ”๊ฐ€๊ฐ€ ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.
์ด ๋ง์ธ ์ฆ‰, ์ฃผ๋‹ˆํ•˜๋ž‘์ด ๋งŒ๋“  Deployment๋Š” pod๊ฐ€ ํ•˜๋‚˜ ๋ฌถ์—ฌ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜๊ณ  ์žˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.

์ด๋ฒˆ์—๋Š” ํ•ด๋‹น Pod๋ฅผ ๋‹ค์‹œ ์‚ญ์ œํ•ด ๋ณผ๊ฒŒ์š”.



๋ถ„๋ช…ํžˆ pod๋ฅผ ์‚ญ์ œํ–ˆ์ง€๋งŒ, ๋‹ค์‹œ Pod ๋ชฉ๋ก์„ ์กฐํšŒํ–ˆ์„ ๋•Œ, Pod๊ฐ€ ๊ธฐ๋™ ์ค‘ ์ธ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.
ํ˜„์žฌ ๊ธฐ๋™์ค‘์ธ Pod๋Š” ์œ„์—์„œ ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์‚ญ์ œํ•œ Pod๊ฐ€ ์•„๋‹Œ ๊ฒƒ์€ ํ™•์‹คํ•ด์š”.

์ด๊ฒƒ์€ Deploymnet๋กœ pod๋ฅผ ๋ฌถ์–ด ์‹คํ–‰ํ•  ๊ฒฝ์šฐ Deploymnet๋Š” ์ตœ์†Œ ์œ ์ง€ Pod ๊ฐœ์ˆ˜๋ฅผ ๊ณ„์† ์œ ์ง€ํ•˜๋ ค๊ณ  ํ•˜๋Š” ์„ฑ์งˆ์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”. 

๋”ฐ๋ผ์„œ Pod์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๋ฉด Deployment๋ฅผ ๋งŒ๋“ค ๋•Œ, ์ œ์‹œํ–ˆ๋˜ ๊ฐœ์ˆ˜๋งŒํผ์€ ๋ฌด์กฐ๊ฑด Pod๋ฅผ ์œ ์ง€ํ•ด์ค€๋‹ต๋‹ˆ๋‹ค.




kubectl scale deployment {deployment ์ด๋ฆ„} --replicas={ํฌ๋ง Deployment ๊ฐœ์ˆ˜}


์ด๋ฒˆ์—๋Š” Deployment์— ๋Œ€ํ•œ Scale ์ž‘์—…์„ ํ•ด ๋ณผ๊ฒŒ์š”.
์œ„์˜ ๋ช…๋ น์–ด๋Š” Deployment์—์„œ ์œ ์ง€ํ•˜๊ณ ์ž ํ•˜๋Š” Pod ๊ฐœ์ˆ˜๋ฅผ ํ•˜๋‚˜ ๋” ๋Š˜๋ ค์ฃผ๋Š” ๊ฒƒ์ด์—์š”.


kubectl get pods


๋‹ค์‹œ Pod ๋ชฉ๋ก์„ ํ™•์ธํ•ด๋ณด๋‹ˆ Pod๊ฐ€ ํ•˜๋‚˜ ๋” ์ƒ๊ธด๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
Pod๋Š” Container๋ผ๊ณ  ๋งํ• ์ˆœ ์—†์–ด์š”.
์™œ๋ƒํ•˜๋ฉด Pod์—๋Š” Container๊ฐ€ ํ•˜๋‚˜๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜๋„ ์žˆ๊ณ , ์—ฌ๋Ÿฌ ๊ฐœ๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.

 

kubectl get deployments


์ด๋ฒˆ์—” Deployment ๋ชฉ๋ก์„ ํ™•์ธํ•ด ๋ณด์•˜์–ด์š”.
READY์— 1/1์ด ์•„๋‹Œ 2/2๋ผ๊ณ  ํ‘œ์‹œ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ด๋Š” 2๊ฐœ์˜ Pod๋ฅผ ์œ ์ง€ํ•  ๊ฒƒ์ด๊ณ , 2๊ฐœ์˜ Pod๊ฐ€ ์ •์ƒ ์ž‘๋™์ค‘์ด๋ผ๋Š” ์˜๋ฏธ์—์š”.


Scaling ์ž‘์—…์€ ์ˆซ์ž๋ฅผ ๋Š˜๋ฆด ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์ค„์ผ์ˆ˜๋„ ์žˆ์–ด์š”.


์œ„์™€ ๊ฐ™์ด Pod ๊ฐœ์ˆ˜๊ฐ€ ํ•˜๋‚˜ ์ค„์–ด๋“  ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



kubectl delete deployment.apps/{deployment ์ด๋ฆ„}


์œ„์™€ ๊ฐ™์ด Deployment๋ฅผ ์‚ญ์ œํ•ด ์ค„ ์ˆ˜๋„ ์žˆ์–ด์š”.






        ๐Ÿ“ฆ Script ๋งŒ๋“ค์–ด ๊ฐ€์ง€๊ณ  ๋†€๊ธฐ

์ด๋ฒˆ์—๋Š” ์œ„์—์„œ ๊ณต๋ถ€ํ–ˆ๋˜ ๋‚ด์šฉ์„ Script๋กœ ํ•œ ๋ฐฉ์— ๋งŒ๋“ค์–ด์„œ ๊ฐ€์ง€๊ณ  ๋…ธ๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณผ๊ฒŒ์š”.


GUI ํ˜•ํƒœ์ธ Text Editor๋ฅผ ํ†ตํ•ด ์ž‘์„ฑํ•ด๋„ ๋˜์ง€๋งŒ ์ฃผ๋‹ˆํ•˜๋ž‘์€ vim์„ ํ†ตํ•ด CLI ํ˜•ํƒœ๋กœ ์ž‘์„ฑ์„ ํ•ด๋ณด๋ คํ•ด์š”.

sample1.yml



์œ„์˜ yaml Script๋Š” ํฌ๊ฒŒ 4๊ฐ€์ง€ Part๋กœ ๊ตฌ๋ถ„์ด ๋˜์–ด ์žˆ๋Š” ๊ฒƒ์ด์—์š”.

1. apiVersion
   โˆ™ ์–ด๋–ค Object ์ฆ‰, Pod๋‚˜, Deployment๋ฅผ ๋งŒ๋“ค ๊ฒƒ์ธ์ง€์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง€๊ฒ ์œผ๋‚˜, ์ผ๋ฐ˜์ ์œผ๋กœ Pod, Deployment,
        Service์˜ ๊ฒฝ์šฐ apps/v1์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉ.

2. kind
   โˆ™ ๋งŒ๋“ค๊ณ ์ž ํ•˜๋Š” Kubernetes Object ์ด๋ฆ„ ๋ช…์‹œ.

3. metadata
   โˆ™ ์ž‘์„ฑํ•˜๋Š” Script์˜ ์ด๋ฆ„, Labeling ์ž‘์—…
      - Labeling์„ ํ•ด ์ค€๋‹ค๋ฉด ์ž์œ ๋กญ๊ฒŒ Key์™€ Value ํ˜•ํƒœ๋กœ ์ง€์ •์„ ํ•˜๊ณ , ๋‹ค๋ฅธ ์ž์›์—์„œ ํ˜„์žฌ ๋งŒ๋“ค๊ณ  ์žˆ๋Š” ์ž์›์„ ์„ ํƒํ•˜์—ฌ
         ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ์–ด๋–ค ๊ฐ’์„ ๋ฐ˜์˜ํ•  ๋•Œ ๋“ฑ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ง€์ •.

4. spec
   โˆ™ kind ์ฆ‰, Kubernetes Object ๋งˆ๋‹ค ์ž‘์„ฑ๋ฒ•์ด ๋‹ฌ๋ผ์ง.
      - Pod์˜ ๊ฒฝ์šฐ ์–ด๋–ค Container๋ฅผ ์“ธ ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•ด ์ •์˜.
      - Deployment์˜ ๊ฒฝ์šฐ Deployment์— ํ•„์š”ํ•œ Option ์ •์˜.

   โˆ™ replicas:2 ๋ผ๊ณ  ํ•˜๋ฉด ์ƒ์„ฑํ•˜๊ณ ์ž ํ•˜๋Š” Deployment๋Š” ์œ ์ง€ํ•˜๊ณ ์ž ํ•˜๋Š” Pod์˜ ๊ฐœ์ˆ˜๋ฅผ 2๊ฐœ๋กœ ์„ค์ •.
   โˆ™ selector(๋Œ€์ƒ ์ •์˜) : ํ˜„์žฌ ์ž‘์—…ํ•˜๊ณ ์ž ํ•˜๋Š” ๋Œ€์ƒ์— ๋Œ€ํ•ด ์–ด๋–ค Lable์— ๋ช…์‹œํ•  ๊ฒƒ์ธ์ง€ ์ •์˜.
   โˆ™ template: ์‹ค์ œ Deployment๋ฅผ ํ†ตํ•ด ๋งŒ๋“ค๊ณ ์ž ํ•˜๋Š” Pod ๋‚ด์šฉ ์ •์˜.
      - spec: containers: -name: ์„ค์น˜ํ•˜๊ณ ์ž ํ•˜๋Š” Container์ด๋ฆ„ ์ •์˜ ๋ฐ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” Imate ์ •์˜.
      - spec: containers: ports: Container๊ฐ€ ์‚ฌ์šฉํ•  Port ์ง€์ •.


apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80



kubectl apply -f {Script File Name}


์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Script๋ฅผ ๊ธฐ๋™ ์‹œ์ผœ ๋ณด์•˜์–ด์š”.

์ฐธ๊ณ ๋กœ -f Options์€ File์ด๋ผ๋Š” Option์ด๊ณ , Script File ๋ช…์„ ๋’ค์— ์ ๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์—์š”.




ํ˜„์žฌ ์ฃผ๋‹ˆํ•˜๋ž‘์˜ Mac Book์—์„œ ๊ธฐ๋™์ค‘์ธ Kubernetes์˜ Object ๋ชฉ๋ก๋“ค์„ ์ถœ๋ ฅํ•ด ๋ณด์•˜์–ด์š”.


 

 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
kubectl get pods -o wide


Pod ์ •๋ณด๋ฅผ ์ข€ ๋” ์ž์„ธํ•˜๊ฒŒ ํ™•์ธํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉ.



Pod์— ์ ‘์†ํ•˜๊ณ ์ž ํ•  ๋•Œ๋Š” Docker์—์„œ exec -it ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ–ˆ๋“ฏ์ด ๋น„์Šทํ•œ ๋ช…๋ น์–ด๋กœ Pod์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ์–ด์š”.

kubectl exec -it {Pod ์ด๋ฆ„} -- {์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” Shell}

 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
exec -it Option

i : Interactive
t : tty

Keyboard ์ƒ์— ์ž…๋ ฅํ•œ ๊ฐ’์„ Terminal์— ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” Option

 

 


์ ‘์†๋œ Pod์˜ OS๋Š” Debian ๊ณ„์—ด์˜ Linux ์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


apt-get update


apt๋ฅผ ํ†ตํ•ด ๋ช‡๊ฐ€์ง€ Tool์„ ๋‚ด๋ ค๋ฐ›๊ธฐ ์œ„ํ•ด ์ตœ์‹ ํ™”๋ฅผ ํ•ด์ฃผ์—ˆ์–ด์š”.


apt-get install -y curl wget


apt๋ฅผ ํ†ตํ•ด curl๊ณผ wget์„ ๋‚ด๋ ค๋ฐ›๊ธฐ ํ•ด ์ฃผ์—ˆ์–ด์š”.


ํ•ด๋‹น Pod์— IP๋ฅผ ํ™•์ธํ•˜๊ณ , Nginx๊ฐ€ ์ •์ƒ ์ž‘๋™์ค‘์ธ์ง€๋ฅผ curl Tool์„ ํ†ตํ•ด ํ™•์ธํ•ด ๋ณด์•˜์–ด์š”.



ํ˜„์žฌ ์ฃผ๋‹ˆํ•˜๋ž‘์˜ Mac Book์œผ๋กœ ์œ„์˜ Pod์— http๋กœ ์ ‘์†์„ ํ•˜๊ฒŒ ๋˜๋ฉด ์—ฐ๊ฒฐ์ด ๋˜์ง€ ์•Š์„๊ฑฐ์—์š”.
์ ‘์†์„ ํ•ด๋ณด๊ธฐ ์œ„ํ•ด ์œ„์™€ ๊ฐ™์ด Port Forwarding ์ž‘์—… ํ•ด์ฃผ๊ณ , Port๋ฅผ 80์œผ๋กœ ์—ด์–ด์ฃผ์—ˆ์–ด์š”.

service ๋ชฉ๋ก์„ ํ™•์ธํ•ด ๋ณด๋‹ˆ nginx-deployment๊ฐ€ ์™ธ๋ถ€์—์„œ๋Š” 30127๋กœ ๋‚ด๋ถ€์—์„œ๋Š” 80์œผ๋กœ Port Forwarding๋œ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด Mac Book ๋ธŒ๋ผ์šฐ์ €๋กœ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.






Deploymenet๋ฅผ ์ผ๋‹จ, ์‚ญ์ œํ•ด ์ฃผ์—ˆ์–ด์š”.



๋˜ํ•œ ํ•ด๋‹น Service๋„ ์‚ญ์ œํ•ด ์ฃผ์—ˆ์–ด์š”.




cicd-devops-deployment.yml

 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cicd-deployment
spec:
  selector:
    matchLabels:
      app: cicd-devops-project
  replicas: 2

  template:
    metadata:
      labels:
        app: cicd-devops-project
    spec:
      containers:
      - name: cicd-devops-project
        image: edowon0623/cicd-project-ansible
        imagePullPolicy: Always
        ports:
        - containerPort: 8080


์ผ๋‹จ! ์œ„์™€ ๊ฐ™์ด ๋˜ ๋‹ค๋ฅธ yml File์„ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.



cdcd-devops-service.yml

 

apiVersion: v1
kind: Service
metadata:
  name: cicd-service
  labels:
    app: cicd-devops-project
spec:
  selector:
    app: cicd-devops-project
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 32000


๊ทธ๋Ÿฐ ๋’ค ์œ„์™€ ๊ฐ™์ด service Object๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ๋Š”๋ฐ, Deployment๋กœ ๋งŒ๋“  Ansible์„ ์™ธ๋ถ€์—์„œ ์ด์šฉํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•จ์ด์—์š”.

์œ„์— Script ์ค‘ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์€ ๋‚ด๋ถ€ 8080 Port๋ฅผ ์™ธ๋ถ€ 8080์œผ๋กœ Port Forwarding ํ•˜๋Š” ๋ถ€๋ถ„์ด์—์š”.

์‹ค์ œ Node์— ์ ‘์†ํ•  ๋•Œ๋Š” 32000 Port๋ฅผ ์ด์šฉํ•˜๊ฒ ๋‹ค๊ณ  ์ถ”๊ฐ€ ํ•ด ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.





ls -al


์œ„ ๋‘๊ฐ€์ง€ Script๋ฅผ ์ž‘๋™์‹œ์ผœ ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.



kubectl apply -f cicd-devops-deplyment.yml


์œ„์™€ ๊ฐ™์ด deployment๋ฅผ ๋จผ์ € ์ƒ์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.

๋งŒ์•ฝ READY๊ฐ€ 0/2 ๋“ฑ๊ณผ ๊ฐ™์ด ๋น„์ •์ƒ์  ํ‘œ์‹œ๊ฐ€ ๋œ๋‹ค๋ฉด Image๋ฅผ ๋‚ด๋ ค๋ฐ›๊ณ , Pod๋ฅผ ๋งŒ๋“œ๋Š๋ผ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.


kubectl get pods


Pod ๋“ค์ด ์ž˜ ์ƒ๊ฒจ๋‚œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


kubectl apply -f cicd-devops-service.yml


๋งŒ์•ฝ ์œ„์™€ ๊ฐ™์ด Error๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด yml ๋“ค์—ฌ์“ฐ๊ธฐ๋‚˜, ์˜คํƒ€๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•  ํ•„์š”๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.




์œ„์™€ ๊ฐ™์ด Service Object๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋Š” Script๋ฅผ ๊ธฐ๋™ํ•ด ์ฃผ์—ˆ์–ด์š”.



kubectl get services


Service Object ๋ชฉ๋ก์„ ํ™•์ธํ•ด ๋ณด์•˜๋”๋‹ˆ ์œ„์™€ ๊ฐ™์ด cicd-service๊ฐ€ NodePort Type์œผ๋กœ Port Forwarding๊นŒ์ง€ ์™„๋ฒฝํ•˜๊ฒŒ ๋œ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด ๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ†ตํ•ด ์ด ์ „์— Docker์™€ Jenkins ์—ฐ๋™์„ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ๋งŒ๋“ค์–ด๋‘์—ˆ๋˜ Docker Image๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ž˜ ๋ฐ›์•„์™€ ์กŒ๊ณ , Container๋กœ ์ž˜ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.






    ๐Ÿ”ฝ  Kubernetes์™€ Ansible

        ๐Ÿ“ฆ ์—ฐ๋™

 

์ด๋ฒˆ ์ž‘์—…์€ ์ด ์ „์— CentOS7์— ๊ฐ€์ƒํ™” CentOS7์— Kubernetes Master๋ฅผ ์˜ฌ๋ฆฐ ๊ณณ์—์„œ ์ž‘์—…์„ ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.
CentOS7์— Kubernetes๋ฅผ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์ด ๊ณณ์— ์ •์„ฑ์Šค๋Ÿฝ๊ฒŒ ์ค€๋น„ํ•ด ๋‘์—ˆ์–ด์š”.

 


์ด๋ฒˆ์—๋Š” ์ด ์ „ ์‹œ๊ฐ„์— ๊ณต๋ถ€ ํ–ˆ๋˜ Ansible์„ ์ด์šฉํ•ด์„œ Kubernetes์— ์ ‘์†ํ•œ ๋’ค Playbook์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.



 

Jenkins๋ฅผ ํ†ตํ•ด Ansible์— ssh๋ฅผ ์ด์šฉํ•˜์—ฌ Ansible์˜ Playbook์ด ๋™์ž‘ํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์ „๋‹ฌํ•˜๊ณ , ํ•ด๋‹น Playbook์„ ์ด์šฉํ•˜์—ฌ Kubernetes Cluster์— ๋ช…๋ น์–ด๋ฅผ ์ „๋‹ฌํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.

ํ˜น์€ Jenkins์—์„œ ๋ฐ”๋กœ Kubernetes ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด์„œ Cluster์— ๋ช…๋ น์–ด๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜๋„ ์žˆ์–ด์š”.


 
๋จผ์ € ์ฃผ๋‹ˆํ•˜๋ž‘์€ Ansible Server์—์„œ k8s-master Server๋กœ ssh ์ ‘์† Test๋ฅผ ์ง„ํ–‰ํ•ด ๋ณด์•˜์–ด์š”.

์ฐธ๊ณ ๋กœ ํ˜„์žฌ Ansible์€ ์ฃผ๋‹ˆํ•˜๋ž‘์˜ Synology NAS Docker๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๊ณ , Kubernetes Master Server๋Š” Laptop์— CentOS7์„ ์˜ฌ๋ฆฌ๊ณ , ๊ทธ ์•ˆ์— ๊ฐ€์ƒ ๋จธ์‹ ์œผ๋กœ CentOS7์„ ๋‹ค์‹œ ์˜ฌ๋ ค์„œ ๊ตฌ์„ฑ์„ ํ•ด ๋†จ๊ธฐ ๋•Œ๋ฌธ์— VPN์„ ํ†ตํ•ด ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ตฌ์„ฑ์„ ํ•˜๊ณ  ์ง„ํ–‰ํ•˜๊ณ  ์žˆ์–ด์š”.



Ansible Server์— Root Directory์—์„œ K8s๋ผ๋Š” Directory๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.


vim ~/k8s/hosts


k8s Directory์— hosts๋ผ๋Š” File์„ ๋งŒ๋“ค์–ด์ฃผ๊ณ , ์œ„์™€ ๊ฐ™์ด K8s-master ์ •๋ณด๋ฅผ ์ •์˜ํ•ด ์ฃผ์—ˆ์–ด์š”.



ssh-keygen

 

ssh-copy-id {๊ณ„์ •์ด๋ฆ„}@{Server IP}

 

์ด๋ฒˆ์—๋Š” Ansible Server์—์„œ k8s๋กœ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด SSH ๊ณต๊ฐœํ‚ค๋ฅผ ๋งŒ๋“ค์–ด์„œ ์ „๋‹ฌํ•ด ์ฃผ์—ˆ์–ด์š”.-

 

ansible -i ~/k8s/hosts kubernetes -m ping

 

Ansible hosts๋กœ ๋“ฑ๋กํ•œ Kubernetes Group์— Kuberntest Master Node์— Ping Test๋ฅผ ์ง„ํ–‰ํ•ด ๋ณด์•˜์–ด์š”.


vim ~/k8s-cicd-deployment-playbook.yml

 

- name: Create pods using deployment 
  hosts: kubernetes 
  # become: true
  # user: ubuntu
 
  tasks: 
  - name: create a deployment
    command: kubectl apply -f cicd-devops-deployment.yml




๋จผ์ € Ansible Server์—์„œ Kubernetes ๋™์ž‘์„ ์ •์˜ํ•  Playbook Script๋ฅผ ์œ„์™€ ๊ฐ™์ด ๋งŒ๋“ค์–ด์ฃผ์—ˆ์–ด์š”.

 

์œ„์—์„œ ๋งŒ๋“  hosts File์— ์ •์˜๋œ kubernetes Group์— ๋“ฑ๋ก๋œ Server์—๊ฒŒ cicd-devops-deployment ๋ผ๋Š” yaml Script๋ฅผ ๊ธฐ๋™ํ•˜๋„๋ก ๋งŒ๋“  Script์—์š”.


vim ~/cicd-devops-deployment.yml



apiVersion: apps/v1
kind: Deployment
metadata:
  name: cicd-deployment

spec:
  selector:
    matchLabels:
      app: cicd-devops-project

  replicas: 2

  template:
    metadata:
      labels:
        app: cicd-devops-project

    spec:
      containers:
      - name: cicd-devops-project
        image: junyharang/cicd-project-ansible
        imagePullPolicy: Always
        ports:
        - containerPort: 8080


์ด๋ฒˆ์—๋Š” Kubernetes Master Server์— Deployment๋ฅผ ์ƒ์„ฑํ•˜๋Š” yml Script๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.




ansible-playbook -i ~/k8s/hosts k8s-cicd-deployment-playbook.yml


์œ„์™€ ๊ฐ™์ด playbook Script๋ฅผ ๊ธฐ๋™์‹œ์ผœ ์ฃผ๋‹ˆ ์ •์ƒ์ ์œผ๋กœ ์ž‘์—…์ด ๋˜์—ˆ๋‹ค๊ณ  ๋‚˜์™”์–ด์š”.

 

kubectl get all


Kubernetes Master Server์—์„œ Pod์™€ Deployment ๋ชฉ๋ก์„ ์กฐํšŒํ•ด ๋ณด๋‹ˆ ์œ„์™€ ๊ฐ™์ด pod 2๊ฐœ๊ฐ€ ๋งŒ๋“ค์–ด์ง„ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



vim ~/k8s-cicd-service-playbook.yml

 

์ด๋ฒˆ์—๋Š” Kubernetes Service Object๋ฅผ ๋งŒ๋“ค playbook Script๋ฅผ ์œ„์™€ ๊ฐ™์ด ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.



vim ~/cicd-devops-service.yml


Kubernetes Server์—์„œ ์œ„์™€ ๊ฐ™์ด Service Object์— ๋Œ€ํ•œ Script๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.



kubectl get service

 

์œ„์˜ Script๋ฅผ ๊ธฐ๋™ํ•˜๊ธฐ ์ „ Kubernetes Master Server์—์„œ Service ๋ชฉ๋ก์„ ์กฐํšŒํ•ด ๋ณด์•˜์–ด์š”.



ansible-playbook -i ~/k8s/hosts k8s-cicd-service-playbook.yml


Ansible Server์—์„œ Service Object ๊ด€๋ จ Script๋ฅผ ๊ธฐ๋™์‹œ์ผœ ์ฃผ์—ˆ์–ด์š”.



kubectl get service

 

Kubernetes Master Server์—์„œ Service ๋ชฉ๋ก์„ ๋‹ค์‹œ ์กฐํšŒํ•ด ๋ณด๋‹ˆ ์œ„์™€ ๊ฐ™์ด cicd-service๋ผ๋Š” ๊ฒƒ์ด ์ƒ๊ธด ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด ๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ†ตํ•ด์„œ๋„ ์ ‘์†๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

 








    ๐Ÿ”ฝ  Kubernetes์™€ Jenkins

        ๐Ÿ“ฆ ์—ฐ๋™

์ฃผ๋‹ˆํ•˜๋ž‘์€ Kubernetes์™€ Ansible ์—ฐ๋™์—์„œ ์ด ์ „์— CentOS 7์— ๊ฐ€์ƒํ™”๋กœ CentOS7์„ ์˜ฌ๋ฆฌ๊ณ , ๊ทธ ๊ณณ์— ๋งŒ๋“ค์—ˆ๋˜ Kubernetes Master๋ฅผ ์ด์šฉํ–ˆ์—ˆ๋Š”๋ฐ, ์ด๋ฒˆ์—๋Š” ์ฃผ๋‹ˆํ•˜๋ž‘์˜ Mac Book์—์„œ Docker Desktop์„ ํ†ตํ•ด MiniKube๋ฅผ ์ด์šฉํ•œ ๋ฐฉ์‹์œผ๋กœ ์ž‘์—…์„ ํ•ด๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

์ด๋ฒˆ์—๋Š” Ansible์„ ์ด์šฉํ•˜์ง€ ์•Š๊ณ , Jenkins์—์„œ ๋ฐ”๋กœ Kubernetes ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ•œ์ง€ ๊ณต๋ถ€ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.



 



์ž‘์—…์„ ์‹œ์ž‘ํ•˜๊ธฐ ์ „ ์œ„์—์„œ ์ง„ํ–‰ํ•ด์„œ ๋งŒ๋“ค์–ด์ง„ ๋‚ด์šฉ์€ ๋ชจ๋‘ ์‚ญ์ œ๋ฅผ ํ•ด ์ฃผ์—ˆ์–ด์š”.





Jenkins ๊ด€๋ฆฌ -> ์‹œ์Šคํ…œ ์„ค์ •

 

SSH Server -> ์ถ”๊ฐ€


์œ„์™€ ๊ฐ™์ด Jenkins ์‹œ์Šคํ…œ ์„ค์ •์—์„œ SSH Server๋ฅผ ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€ํ•ด ์ค„๊ฒŒ์š”.
์ด ๊ณณ์—์„œ Kubernetes Master์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ธฐ์ž…ํ•ด ์ค„ ๊ฒƒ์ด์—์š”.


์ฃผ๋‹ˆํ•˜๋ž‘์€ Mac Book์— Minikube๋ฅผ ๊ตฌ์„ฑํ•˜์˜€๊ณ , ์ด๊ฒƒ์„ ํ†ตํ•ด Test๋ฅผ ํ•  ๊ฒƒ์ด์—์š”.
๊ทธ๋ž˜์„œ username์€ ์ฃผ๋‹ˆํ•˜๋ž‘์ด Mac Book Login ์‹œ์— ์‚ฌ์šฉํ•˜๋Š” ๊ณ„์ •์„ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ๊ณ , Mac Book์˜ IP๋ฅผ Hostname์— ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.

Remote Directory๋Š” ํ˜„์žฌ ์ฃผ๋‹ˆํ•˜๋ž‘์ด Mac Book์—์„œ ๊ด€๋ จ ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•˜๋Š” Directory๋กœ ์ง€์ •ํ•ด์ฃผ์—ˆ์–ด์š”.

์—ฌ๊ธฐ๊นŒ์ง€ ์™„์„ฑ ๋˜์—ˆ์œผ๋ฉด '๊ณ ๊ธ‰'์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.


user password ...


์œ„์˜ use password ... Check Box๋ฅผ ํ™œ์„ฑํ™” ํ•œ ๋’ค Password์— ์ฃผ๋‹ˆํ•˜๋ž‘ Mac Book ๊ณ„์ •์ธ junyss์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.



Port๋Š” Minikube๊ฐ€ ์„ค์น˜๋œ PC์˜ ssh Port ๋ฒˆํ˜ธ ํ˜น์€ Kubernetes Master ssh Port ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ๊ณ , Test Configuration Button์„ ๋ˆŒ๋Ÿฌ Success๊ฐ€ ๋œจ๋Š”์ง€ ํ™•์ธํ•ด ์ค๋‹ˆ๋‹ค.


Apply๋ฅผ ๋ˆ„๋ฅด๊ณ , Save๋ฅผ ๋ˆŒ๋Ÿฌ ํ•ด๋‹น ์ฐฝ์„ ๋น ์ ธ๋‚˜์™”์–ด์š”.


์ด๋ฒˆ์—” Item์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ๋ณผ๊ฒŒ์š”.


Item ์ด๋ฆ„์„ ์„ค์ •ํ•˜๊ณ , ์ด ์ „์— ์ž‘์—…ํ–ˆ์—ˆ๋˜ Ansible ์„ค์ •์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด ์œ„์™€ ๊ฐ™์ด ํ•œ ๋’ค 'OK'๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์—ˆ์–ด์š”.


๋นŒ๋“œ ํ›„ ์กฐ์น˜

 

๋นŒ๋“œ ํ›„ ์กฐ์น˜์—์„œ SSH Publishers์— SSH Server๋ฅผ ์œ„์—์„œ ์„ค์ •ํ–ˆ๋˜ mac-minikube๋กœ ์„ ํƒ์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.


 

์•„์ง Github์— ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์“ธ ๊ฒƒ์€ ์•„๋‹ˆ๋ผ์„œ Source files์— ์„ค์ •์€ ํฌ๊ฒŒ ์ค‘์š”ํ•˜์ง€ ์•Š์€ ๊ฒƒ์ด์—์š”.

Minikube๊ฐ€ ์„ค์น˜๋œ Mac Book์— ์ž‘์—… Directory Path๋ฅผ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋กœ Remote directory์— ์ ์–ด์ฃผ๊ณ ,

Exec command์— kubectl์„ ์ด์šฉํ•ด์„œ Script๊ฐ€ ์ž‘๋™๋˜๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.

๋ช…๋ น์–ด์—์„œ Kubectl ๋ช…๋ น์–ด๊ฐ€ ์œ„์น˜ํ•œ ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ๋Š”๋ฐ, Mac Book, Windows ๋ฅผ ํ†ตํ•œ Minikube ์‚ฌ์šฉ์‹œ์—๋Š” ์ €๋ ‡๊ฒŒ ํ•˜์ง€ ์•Š์œผ๋ฉด Error๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋กœ ์ ์–ด์ฃผ๋Š” ๊ฒƒ์ด ์ข‹์•„์š”.


๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ

Mac OS kubectl ์œ„์น˜ 




Build๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์ฒ˜๋ฆฌ ๋˜์—ˆ์–ด์š”.

 

kubectl get all


Minikube๊ฐ€ ์„ค์น˜๋œ Mac Book์—์„œ ํ™•์ธํ•ด๋ณด๋‹ˆ ์œ„์™€ ๊ฐ™์ด Pod์™€ Deployment๊ฐ€ ๋งŒ๋“ค์–ด์ง„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



์ด๋ฒˆ์—๋Š” Jenkins์™€ Ansible ๊ทธ๋ฆฌ๊ณ , Kubernetes ๋ชจ๋‘๋ฅผ ์ด์šฉํ•˜๋Š” ์ž‘์—…์„ ํ•ด ๋ณผ๊ฒŒ์š”.
์ตœ์ดˆ Item ํ•˜๋‚˜๋ฅผ ๋งŒ๋“ค์–ด์ค„๊ฒŒ์š”.


 


์ด๋ฒˆ์—๋Š” ๋นŒ๋“œ ํ›„ ์กฐ์น˜์—์„œ ์œ„์™€ ๊ฐ™์ด ์ด ์ „์— ๋งŒ๋“ค์—ˆ๋˜ ansible-host๋ฅผ ์„ ํƒํ•ด ์ฃผ์—ˆ์–ด์š”.


Exec command ๋ถ€๋ถ„์—๋Š” play book์„ ๊ธฐ๋™ํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์—ˆ๋Š”๋ฐ, -u Option์€ ๋Œ€์ƒ Server ์—ฌ๊ธฐ์„œ๋Š” ์ฃผ๋‹ˆํ•˜๋ž‘์˜ Mac Book์ด๊ณ , ํ•ด๋‹น Server์— ๊ณ„์ •์„ ์ž…๋ ฅํ•ด ์ฃผ๋ฉด ๋˜์š”.

๋งŒ์•ฝ root๋ผ๋ฉด ์ƒ๋žต ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

Apply๋ฅผ ๋ˆ„๋ฅธ ๋’ค ์ €์žฅ์„ ํ•ด์„œ ํ•ด๋‹น ์ฐฝ์„ ๋‚˜์™€์ค„๊ฒŒ์š”.
๊ทธ๋Ÿฐ ๋’ค Build ์ž‘์—…์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.


 


์ž‘์—…์ด ์‹คํŒจ ํ•˜์˜€์–ด์š”.


 


์ด ๋ฌธ์ œ๋Š” Ansible Server์˜ IP๊ฐ€ ๋ฐ”๋€Œ์–ด์„œ ๋ฐœ์ƒ๋œ ๋ฌธ์ œ์—์š”. ์œ„์˜ ํ„ฐ๋ฏธ๋„์—์„œ ifconfig๋ฅผ ํ•˜์˜€์„ ๋•Œ, eth0์˜ IP๊ฐ€ 172.17.0.5์ด์ง€๋งŒ, Jenkins์— ์„ค์ •๋œ IP ์ฃผ์†Œ๋Š” 172.17.0.6์ธ ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์–ด์š”.

Jenkins์— ์„ค์ • IP๋ฅผ 5๋กœ ๋ฐ”๊พธ์–ด ์ค„๊ฒŒ์š”.



๋ณ€๊ฒฝ ๋’ค Test๊นŒ์ง€ ์ •์ƒ์ ์œผ๋กœ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์—ˆ์–ด์š”.




์ถ”๊ฐ€์ ์œผ๋กœ service Object ์ž‘์—…์— ๋Œ€ํ•œ Script ๋ช…๋ น์–ด๋ฅผ ์œ„์™€ ๊ฐ™์ด ์ƒ์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.








        ๐Ÿ“ฆ ์ „์ฒด CI/CD ์ž๋™ํ™” Process ๊ตฌ์„ฑ


CI(Continuous Integration)๋Š” ์ง€์†์ ์ธ ํ†ตํ•ฉ์ด๋ผ๋Š” ๋œป์œผ๋กœ ํ˜•์ƒ ๊ด€๋ฆฌ ์†”๋ฃจ์…˜์— ์šฐ๋ฆฌ๊ฐ€ ๋งŒ๋“  Code๋ฅผ Push ์ฆ‰, ์˜ฌ๋ฆฌ๊ฒŒ ๋˜๋ฉด ํ™˜๊ฒฝ์— ๋งž์ถ”์–ด Build๋ฅผ ํ•˜๋ฉด์„œ ํ•„์š”์— ๋”ฐ๋ผ Unit Test(๋‹จ์œ„ ํ…Œ์ŠคํŠธ)๋ฅผ ํ•˜๊ฒŒ ๋  ๊ฒƒ์ด๊ณ , ์ด์ƒ์ด ์—†๋‹ค๋ฉด Packaging File์„ ๋งŒ๋“ค๊ฒŒ ๋  ๊ฒƒ์ด์—์š”.

๊ทธ๋Ÿฐ ๋’ค ๋ฐฐํฌํ•˜๊ณ ์ž ํ•˜๋Š” Server์— ๋ฐฐํฌ๋ฅผ ํ•˜๊ฒŒ ๋  ๊ฒƒ์ด์—์š”.

์—ฌ๊ธฐ๊นŒ์ง€ ์ž‘์—…์„ CI๋ผ๊ณ  ๋ถ€๋ฅด๋Š” ๊ฒƒ์ด์—์š”.

CD(Continuous Delivery & Continouos Deployment)์€ ์ง€์†์  ๋ฐฐํฌ








    ๐Ÿ”ฝ  Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD ์ž๋™ํ™” ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ•

        ๐Ÿ“ฆ ์ฒซ๋ฒˆ์งธ ์ด์•ผ๊ธฐ

 

- hosts: all
#   become: true

  tasks:
  - name: create a docker image with deployed war file
    command: docker build -t junyharang/cicd-project-ansible .
    args:
        chdir: /root

  - name: push the image on Docker Hub
    command: docker push junyharang/cicd-project-ansible
    ignore_erros: yes

  - name: remove the docker image from the ansible server
    command: docker rmi junyharang/cicd-project-ansible
    ignore_errors: yes



์ตœ์ดˆ ์ด ์ „์— Ansible์—์„œ ๋งŒ๋“ค์–ด ๋‘์—ˆ๋˜ Docker image๋ฅผ ์ƒ์„ฑํ•˜๋Š” Script๋ฅผ ์ด์šฉํ•  ๊ฒƒ์ด์—์š”.

์ˆ˜์ • ์ „

 

์ˆ˜์ • ํ›„



๋˜ํ•œ ์ด ์ „์— ๋งŒ๋“ค์–ด ๋‘์—ˆ๋˜ Dockerfile์„ ์ด์šฉํ•  ๊ฒƒ์ธ๋ฐ, ์—ฌ๊ธฐ์—์„œ ์ฃผ๋‹ˆํ•˜๋ž‘์€ tomcat์ด ์•„๋‹Œ Nginx๋ฅผ ์ด์šฉํ•˜๋„๋ก ์ˆ˜์ •์„ ํ•ด ์ฃผ์—ˆ์–ด์š”.


 



ํ˜„์žฌ ์ฃผ๋‹ˆํ•˜๋ž‘ Mac Book์—์„œ ๊ธฐ๋™์ค‘์ธ pod์™€ deployment๋ฅผ ํ™•์ธํ•ด ์ฃผ์—ˆ๊ณ , ๋ชจ๋‘ ์‚ญ์ œ๋ฅผ ํ•ด ์ฃผ์—ˆ์–ด์š”.




Jenkins์—์„œ ์œ„์™€ ๊ฐ™์ด Item์„ ํ•˜๋‚˜ ์ƒ์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.



์ˆ˜์ •ํ•œ ๋ถ€๋ถ„์€ Exec command ๋ถ€๋ถ„์ธ๋ฐ, image๋ฅผ ๋งŒ๋“œ๋Š” Script๋ฅผ ์‹คํ–‰๋˜๊ฒŒ ํ•˜๊ณ , ์˜ค์ง Ansible Server์—์„œ๋งŒ ์ž‘๋™๋˜๊ฒŒ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.


์ €์žฅํ•˜๊ณ  ํ•ด๋‹น ์ฐฝ์„ ๋‚˜๊ฐ€์ค€ ๋’ค Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณด์•˜์–ด์š”.




 


์ด๋ฒˆ์—๋„ ์ž‘์—…์ด ์‹คํŒจํ•˜์˜€์–ด์š”. ์—ญ์‹œ ํ•œ๋ฒˆ์— ์™„๋ฃŒ๋˜๋ฉด ์žฌ๋ฏธ๊ฐ€ ์—†๋Š” ๊ฒƒ์ด์—์š”.

์ด ๋ฌธ์ œ๋ฅผ ์•Œ์•„๋ณด๊ธฐ ์œ„ํ•ด Ansible Server์—์„œ ์ง์ ‘ Jenkins์— ์ž…๋ ฅํ–ˆ๋˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด ๋ณด๊ธฐ๋กœ ํ•˜์˜€์–ด์š”.



๋งŒ์•ฝ ์œ„์™€ ๊ฐ™์ด Error๊ฐ€ ๋‚˜์˜จ๋‹ค๋ฉด yml์— ๋ฌธ๋ฒ•์ด ํ‹€๋ฆฐ ๊ฒƒ์ด์—์š”.



์œ„์™€ ๊ฐ™์ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์–ด์š”.


ssh-copy-id {๊ณ„์ •}@{๋Œ€์ƒ Server IP}


Ansible ์ž๊ธฐ ์ž์‹ ์—๊ฒŒ ssh ์ ‘์† ์‹œ ๊ณ„์ •๋“ฑ์„ ๋ฌป์ง€ ์•Š๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด SSH ๊ณต๊ฐœํ‚ค๋ฅผ ์ €์žฅํ•ด ๋‘๊ณ , ์ง„ํ–‰ํ–ˆ๋”๋‹ˆ ์„ฑ๊ณตํ•˜์˜€์–ด์š”.



Docker Hub์—๋„ ์ •์ƒ์ ์œผ๋กœ Update ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


CI ์ž‘์—…์€ ์ •์ƒ์ ์œผ๋กœ ๋์ด ๋‚ฌ๋‹ค๊ณ  ํŒ๋‹จํ•˜๊ณ , ์ด์ œ CD ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๋„๋ก ํ• ๊ฒŒ์š”.



 

Build other projects



Jenkins์— Item ์„ค์ •์—์„œ '๋นŒ๋“œ ํ›„ ์กฐ์น˜ ์ถ”๊ฐ€' Button์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.
๊ทธ๋Ÿฐ ๋’ค Build other projects๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.

์ด๊ฒƒ์€ Build๊ฐ€ ์™„๋ฃŒ๋œ ๋’ค์— ์–ด๋–ค Project๋ฅผ ์ถ”๊ฐ€๋กœ ์—ฐ๊ณ„ํ•  ๊ฒƒ์ธ์ง€ ์„ ํƒํ•˜๋Š” ๊ณณ์ด์—์š”.



Projects to build์— ์ด ์ „์— ๋งŒ๋“ค์—ˆ๋˜ Ansible์„ ์ด์šฉํ•œ kubernetes ์—ฐ๋™ Project๋ฅผ ์„ ํƒํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด ์ด์•ผ๊ธฐ๋Š” ํ˜„์žฌ Project๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋๋‚˜๋ฉด 'Junyharang-k8s-Porject-Using-Ansible' ์ด๋ผ๋Š” Project๋ฅผ ์ถ”๊ฐ€๋กœ ์‹คํ–‰ํ•ด ๋‹ฌ๋ผ๋Š” ๊ฒƒ์ด์—์š”.


์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•˜๊ณ , ์ €์žฅ์„ ํ•œ ๋’ค ํ•ด๋‹น ์ฐฝ์„ ๋‚˜์™”์–ด์š”.
๊ทธ๋Ÿฐ ๋’ค Build๋ฅผ ์‹คํ–‰ํ•ด ์ฃผ์—ˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด ์ •์ƒ ์ž‘๋™ ํ•˜์˜€์–ด์š”.



Docker Image๋„ Docker Hub์— ์ž˜ ์˜ฌ๋ผ์™€ ์ฃผ์—ˆ์–ด์š”.



Code 15๋ฒˆ์— Version์„ 1.5๋กœ ๋ณ€๊ฒฝํ•˜๊ณ , Git์— Pushํ•ด์„œ ์ž๋™์œผ๋กœ CI / CD๊ฐ€ ์ด๋ค„์ง€๋Š”์ง€ ํ™•์ธํ•ด ๋ณผ๊ฒŒ์š”.






 

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์™„๋ฒฝ ๊ฐ€์ด๋“œ:์ž…๋ฌธ๋ถ€ํ„ฐ ์‹ค์ œ ์šด์šฉ๊นŒ์ง€ ํ•„์š”ํ•œ ๊ธฐ์ˆ  ์ด๋ง๋ผ!

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•