Container/Devops

[Devops] Argo Rollouts를 이용한 Canary 배포

pepe_ 2024. 3. 18. 21:10

※ Argo Rollout 설치는 이전 글 참고

 

[Devops] Argo Rollouts를 이용한 Blue/Green 배포

1. Argo Rollouts 소개 1) Argo Rollouts 이란? Argo rollouts은 Progressive Delivery를 지원하는 툴이다. 쿠버네티스에서 롤아웃 관리를 위한 오픈소스 도구 중 하나로, Kubernetes에서 Blue/Green, Canary 등 배포를 지원

lilylabs.tistory.com

 

1. Canary 배포 테스트

1) Canary Manifest 배포

  • spec.strategy를 canary로 지정한다.
    • maxSurge: 새롭게 배포되는 Pod 비율 (기본값: 25%)
    • maxUnavailable: 업데이트 중에 사용할 수 없는 최대 Pod 수
    • steps. setWeight : 새롭게 배포되는 Pod에 전달되는 트래픽 비율
    • steps.pause: AutoPromotion Time
더보기

steps.pause 옵션

 

spec:
  strategy:
    canary:
      steps:
        - pause: { duration: 10 }     # 10 seconds
        - pause: { duration: 10s }   # 10 seconds
        - pause: { duration: 10m }  # 10 minutes
        - pause: { duration: 10h }   # 10 hours
        - pause: {}                         # Auto Promotion 옵션 비활성화

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollout-canary
spec:
  replicas: 8
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: rollout-canary
  template:
    metadata:
      labels:
        app: rollout-canary
    spec:
      containers:
      - name: rollout-canary-demo
        image: nginx:1.14.2
        imagePullPolicy: Always
        ports:
        - containerPort: 80
  strategy:
    canary:
      maxSurge: "25%"
      maxUnavailable: 0
      steps:
      - setWeight: 25
      - pause: {}    
      
---
apiVersion: v1
kind: Service
metadata:
  name: rollout-canary-svc
spec:
  selector:
    app: rollout-canary
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 80
  • 배포 후 replicas를 8로 설정해두었기 때문에 8개의 pod가 생성된 것을 확인할 수 있다.

2) Manifest 수정

  • 하기와 같이 Manifest를 수정하여 새로운 버전을 배포한다. 
k edit rollouts.argoproj.io -n my-ns rollout-canary
# image: nginx:1.14.2 -> image: nginx:1.25.4 변경
  • 카나리 배포로 새로운 버전의 Pod가 maxSurge 값 만큼 생성된 것을 확인할 수 있다.
    • 새로운 버전의 Pod 수 = 8 * 0.25 (maxSurge값) = 2

3) promote 진행

  • pause: {} 으로 설정되어 있어 수동으로 promote를 진행해야 한다.
  • 수동으로 pomote를 진행하면 기존 버전의 Pod 6개가 삭제되고 새로운 버전으로 생성된다.  
    • pause 값에 시간이 정해져 있으면 해당 시간이 지난 후 자동으로 기존 Pod가 삭제되고 새로운 Pod가 점진적으로 생성된다.
# promote 진행
boc@vm-bastion-hub:~/test$ kubectl argo rollouts promote rollout-canary -n my-ns
rollout 'rollout-canary' promoted

# argo rollouts list 확인
boc@vm-bastion-hub:~$ kubectl argo rollouts list rollout -n my-ns
NAME            STRATEGY   STATUS        STEP  SET-WEIGHT  READY  DESIRED  UP-TO-DATE  AVAILABLE
rollout-canary  Canary     Healthy       2/2   100         8/8    8        8           8 

# pod 확인
# AGE 확인 시 6개의 Pod가 새롭게 생성된 것을 확인할 수 있다.
boc@vm-bastion-hub:~$ kubectl get pods -n my-ns 
NAME                              READY   STATUS    RESTARTS   AGE
rollout-canary-76ff85cb7b-4d5lh   1/1     Running   0          33s
rollout-canary-76ff85cb7b-4gpnt   1/1     Running   0          45s
rollout-canary-76ff85cb7b-5hntt   1/1     Running   0          42s
rollout-canary-76ff85cb7b-79t85   1/1     Running   0          13m
rollout-canary-76ff85cb7b-957sz   1/1     Running   0          45s
rollout-canary-76ff85cb7b-ct27h   1/1     Running   0          13m
rollout-canary-76ff85cb7b-h7m4j   1/1     Running   0          32s
rollout-canary-76ff85cb7b-rjvmc   1/1     Running   0          42s