๐น ๋ฐฐํฌ ์ ๋ต์ด ์ค์ํ ์ด์
Kubernetes ํ๊ฒฝ์์ ์ ํ๋ฆฌ์ผ์ด์
์ ๋ฐฐํฌํ ๋,
ํธ๋ํฝ ์์ค ์์ด ์๋ก์ด ๋ฒ์ ์ ์์ ํ๊ฒ ๋ฐฐํฌํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
์ด๋ฅผ ์ํด Argo CD๋ฅผ ํ์ฉํ์ฌ ์๋ํ๋ ๋กค๋ง ์
๋ฐ์ดํธ ๋ฐ ๋ธ๋ฃจ-๊ทธ๋ฆฐ ๋ฐฐํฌ๋ฅผ ์ ์ฉํ ์ ์์ต๋๋ค.
โ Argo CD์์ ๋ฐฐํฌ ์ ๋ต์ ์ ์ฉํด์ผ ํ๋ ์ด์
โ ๋ฌด์ค๋จ ๋ฐฐํฌ(Zero Downtime Deployment) ๊ฐ๋ฅ
โ ํธ๋ํฝ์ ๋ถ์ฐํ์ฌ ๋จ๊ณ์ ์ผ๋ก ๋ฐฐํฌ ์งํ ๊ฐ๋ฅ
โ ๋ฐฐํฌ ์ค ์ฅ์ ๋ฐ์ ์ ์ ์ํ ๋กค๋ฐฑ ๊ฐ๋ฅ
โ GitOps ๋ฐฉ์์ผ๋ก ๋ฐฐํฌ ์ํ๋ฅผ ์ ์งํ๋ฉฐ ๋ณ๊ฒฝ ์ฌํญ์ ์๋์ผ๋ก ๋ฐ์
๐น 1. ๋กค๋ง ์ ๋ฐ์ดํธ(Rolling Update) ์ ์ฉ
๋กค๋ง ์
๋ฐ์ดํธ๋ ๊ธฐ์กด ์ ํ๋ฆฌ์ผ์ด์
์ ์ ์ง์ ์ผ๋ก ์
๋ฐ์ดํธํ๋ ๋ฐฉ์์
๋๋ค.
Kubernetes์ ๊ธฐ๋ณธ ๋ฐฐํฌ ๋ฐฉ์์ผ๋ก ์ ์ง์ ์ผ๋ก ์ ๋ฒ์ ์ ๋ฐฐํฌํ๊ณ , ๊ธฐ์กด ๋ฒ์ ์ Pod๋ฅผ ๊ต์ฒดํฉ๋๋ค.
โ 1.1 ๋กค๋ง ์ ๋ฐ์ดํธ๊ฐ ์ ์ฉ๋ Deployment ์ค์
๐ ๋กค๋ง ์ ๋ฐ์ดํธ Deployment ์์
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app
namespace: example
spec:
replicas: 3 # 3๊ฐ์ Pod ์คํ
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1 # ๋์์ ๋นํ์ฑํ๋ ์ต๋ Pod ์
maxSurge: 1 # ์๋ก ์์ฑํ ์ ์๋ ์ต๋ Pod ์
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-app
image: example-repo/app:v2 # ์๋ก์ด ๋ฒ์
ports:
- containerPort: 80
โ
์ค๋ช
:
โ strategy.type: RollingUpdate → ๋กค๋ง ์
๋ฐ์ดํธ ์ ์ฉ
โ maxUnavailable: 1 → ์
๋ฐ์ดํธ ์ค ํ ๊ฐ์ Pod๊ฐ ๋นํ์ฑํ๋ ์ ์์
โ maxSurge: 1 → ์ ๋ฒ์ ์ Pod๋ฅผ ํ๋์ฉ ์ถ๊ฐํ๋ฉด์ ์ ์ง์ ์ผ๋ก ๊ต์ฒด
โ ๋ฐฐํฌ ์คํ
kubectl apply -f rolling-update.yaml -n example
โ ๋ฐฐํฌ ์ํ ํ์ธ
kubectl rollout status deployment example-app -n example
โ ์ถ๋ ฅ ์์:
deployment "example-app" successfully rolled out
๐น 2. ๋ธ๋ฃจ-๊ทธ๋ฆฐ(Blue-Green) ๋ฐฐํฌ ์ ์ฉ
๋ธ๋ฃจ-๊ทธ๋ฆฐ ๋ฐฐํฌ๋ ํ์ฌ ์คํ ์ค์ธ ์ ํ๋ฆฌ์ผ์ด์
(Blue)๊ณผ ์๋ก์ด ๋ฒ์ (Green)์ ๋์์ ์ด์ํ ํ,
ํ
์คํธ๊ฐ ์๋ฃ๋๋ฉด ํธ๋ํฝ์ ์๋ก์ด ๋ฒ์ (Green)์ผ๋ก ๋ณ๊ฒฝํ๋ ๋ฐฉ์์
๋๋ค.
โ 2.1 ๋ธ๋ฃจ-๊ทธ๋ฆฐ ๋ฐฐํฌ๋ฅผ ์ํ Deployment ์ค์
๐ ๋ธ๋ฃจ-๊ทธ๋ฆฐ ๋ฐฐํฌ Deployment ์์
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app-blue
namespace: example
spec:
replicas: 3
selector:
matchLabels:
app: example-app
version: blue # ๊ธฐ์กด Blue ๋ฒ์
template:
metadata:
labels:
app: example-app
version: blue
spec:
containers:
- name: example-app
image: example-repo/app:v1
ports:
- containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-app-green
namespace: example
spec:
replicas: 3
selector:
matchLabels:
app: example-app
version: green # ์ ๊ท Green ๋ฒ์
template:
metadata:
labels:
app: example-app
version: green
spec:
containers:
- name: example-app
image: example-repo/app:v2
ports:
- containerPort: 80
โ
์ค๋ช
:
โ example-app-blue → ๊ธฐ์กด Blue ๋ฒ์ ์ ์ง
โ example-app-green → ์๋ก์ด Green ๋ฒ์ ๋ฐฐํฌ
โ ๋ฐฐํฌ ์คํ
kubectl apply -f blue-green-deployment.yaml -n example
โ 2.2 ๋ธ๋ฃจ-๊ทธ๋ฆฐ ํธ๋ํฝ ์ ํ์ ์ํ ์๋น์ค ์ค์
๐ ์๋น์ค(ํธ๋ํฝ ์ ํ) ์ค์
apiVersion: v1
kind: Service
metadata:
name: example-app-service
namespace: example
spec:
selector:
app: example-app
version: green # ์ ๊ท Green ๋ฒ์ ์ผ๋ก ํธ๋ํฝ ์ ํ
ports:
- protocol: TCP
port: 80
targetPort: 80
โ
์ค๋ช
:
โ selector.version: green → ํธ๋ํฝ์ ์ ๊ท ๋ฒ์ (Green)์ผ๋ก ๋ณ๊ฒฝ
โ ํธ๋ํฝ ์ ํ ์คํ
kubectl apply -f blue-green-service.yaml -n example
โ ์๋น์ค ์ํ ํ์ธ
kubectl get service example-app-service -n example
โ ์ถ๋ ฅ ์์:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
example-app-service ClusterIP 10.100.200.3 <none> 80/TCP 2m
โ ๊ธฐ์กด Blue ๋ฒ์ ์ ๊ฑฐ(์ต์ข ์ ํ ํ)
kubectl delete deployment example-app-blue -n example
๐น 3. Argo CD๋ฅผ ํ์ฉํ ๋ฐฐํฌ ์๋ํ
Argo CD๋ฅผ ์ฌ์ฉํ๋ฉด ๋กค๋ง ์ ๋ฐ์ดํธ ๋ฐ ๋ธ๋ฃจ-๊ทธ๋ฆฐ ๋ฐฐํฌ๋ฅผ GitOps ๋ฐฉ์์ผ๋ก ์๋ํํ ์ ์์ต๋๋ค.
โ 3.1 Argo CD ์ ํ๋ฆฌ์ผ์ด์ ์ ์
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: example-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/example/repo.git
targetRevision: main
path: blue-green-deployment # ๋ฐฐํฌ ๋ฐฉ์์ด ์ ์๋ Git ๊ฒฝ๋ก
destination:
server: https://kubernetes.default.svc
namespace: example
syncPolicy:
automated:
prune: true
selfHeal: true
โ
์ค๋ช
:
โ repoURL: https://github.com/example/repo.git → GitOps ๋ฐฉ์์ผ๋ก ๋ฐฐํฌ
โ syncPolicy.automated → Git ์ํ ์ ์ง ๋ฐ ์๋ ๋ฐฐํฌ
โ Argo CD๋ฅผ ํ์ฉํ ๋ฐฐํฌ ์คํ
argocd app sync example-app
โ ์ถ๋ ฅ ์์:
Application 'example-app' synchronized
๐น ๊ฒฐ๋ก : ์ด๋ฒ ๊ธ์์ ๋ฐฐ์ด ํต์ฌ ๋ด์ฉ ์ ๋ฆฌ
๐ข ๋กค๋ง ์
๋ฐ์ดํธ(Rolling Update)๋ฅผ ํ์ฉํ์ฌ ์ ์ง์ ์ธ ๋ฐฐํฌ ๊ฐ๋ฅ
๐ข ๋ธ๋ฃจ-๊ทธ๋ฆฐ(Blue-Green) ๋ฐฐํฌ๋ฅผ ์ ์ฉํ์ฌ ์์ ํ ๋ฒ์ ์ ํ ๊ฐ๋ฅ
๐ข Argo CD๋ฅผ ํ์ฉํ์ฌ GitOps ๊ธฐ๋ฐ์ผ๋ก ๋ฐฐํฌ ์๋ํ ๊ฐ๋ฅ
๐ข ํธ๋ํฝ ์ ํ์ ์๋ํํ์ฌ ๋ฐฐํฌ ์ ๋ค์ดํ์์ ์ต์ํํ ์ ์์