Kubernetes Tools/ArgoCD

[Ep.44] [Argo CD ์‹ค๋ฌด ์ ์šฉ #2] Argo CD๋ฅผ ํ™œ์šฉํ•œ ๋กค๋ง ์—…๋ฐ์ดํŠธ ๋ฐ ๋ธ”๋ฃจ-๊ทธ๋ฆฐ ๋ฐฐํฌ

ygtoken 2025. 3. 18. 10:29
728x90

๐Ÿ”น ๋ฐฐํฌ ์ „๋žต์ด ์ค‘์š”ํ•œ ์ด์œ 

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.gitGitOps ๋ฐฉ์‹์œผ๋กœ ๋ฐฐํฌ
โœ” syncPolicy.automated → Git ์ƒํƒœ ์œ ์ง€ ๋ฐ ์ž๋™ ๋ฐฐํฌ

 

โœ… Argo CD๋ฅผ ํ™œ์šฉํ•œ ๋ฐฐํฌ ์‹คํ–‰

argocd app sync example-app

 

โœ… ์ถœ๋ ฅ ์˜ˆ์‹œ:

Application 'example-app' synchronized

๐Ÿ”น ๊ฒฐ๋ก : ์ด๋ฒˆ ๊ธ€์—์„œ ๋ฐฐ์šด ํ•ต์‹ฌ ๋‚ด์šฉ ์ •๋ฆฌ

๐ŸŸข ๋กค๋ง ์—…๋ฐ์ดํŠธ(Rolling Update)๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ ์ง„์ ์ธ ๋ฐฐํฌ ๊ฐ€๋Šฅ
๐ŸŸข ๋ธ”๋ฃจ-๊ทธ๋ฆฐ(Blue-Green) ๋ฐฐํฌ๋ฅผ ์ ์šฉํ•˜์—ฌ ์•ˆ์ „ํ•œ ๋ฒ„์ „ ์ „ํ™˜ ๊ฐ€๋Šฅ
๐ŸŸข Argo CD๋ฅผ ํ™œ์šฉํ•˜์—ฌ GitOps ๊ธฐ๋ฐ˜์œผ๋กœ ๋ฐฐํฌ ์ž๋™ํ™” ๊ฐ€๋Šฅ
๐ŸŸข ํŠธ๋ž˜ํ”ฝ ์ „ํ™˜์„ ์ž๋™ํ™”ํ•˜์—ฌ ๋ฐฐํฌ ์‹œ ๋‹ค์šดํƒ€์ž„์„ ์ตœ์†Œํ™”ํ•  ์ˆ˜ ์žˆ์Œ

 

728x90