Labels를 활용한 Canary Deployment

Yu Sang Min·2025년 5월 12일

K8S

목록 보기
29/32
post-thumbnail

📌 배포방법

  1. 블루 그린 업데이트 (구버전: 블루, 신버전: 그린)
  2. 카나리 업데이트
  3. 롤링 업데이트

🐥 Canary 배포란?

  • 기존 버전을 유지
  • 일부 버전만 신규 버전으로 교체
  • 신규 버전에 버그나 이상이 없는지 확인

🫐 블루 그린 업데이트

  • 블루를 내리고 그린을 기동 👉 서비스 중단 발생

🍭 롤링 업데이트

  • 하나씩 업데이트 👉 무중단 배포

⌨️ Canary 배포 실습

시나리오
1. Deployment 생성

  • replicas 2개
  • labels는
  • app: mainui, version: stable
  • 이름 nginx-stable
  • 이미지 nginx 1.14
  1. Deployment 생성
  • replicas 2개
  • labels는 app: mainui, version: canary
  • 이름 nginx-canary
  • 이미지 nginx 1.15
  1. 단일진입점 생성
  • Service를 80포트
  • labels는 app: mainui
  • 이름 mainui-svc
  1. curl 명령어로 웹페이지 확인 후 canary 버전의 로그 확인
  2. replicas 개수를 canary 3개 stable 1개로 변경하기
# vi nginx-stable.yaml

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

# vi nginx-canary.yaml

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

# vi mainui-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: mainui-svc
spec:
  selector:
    app: mainui
  ports:
  - port: 80
     protocol: TCP
     targetPort: 80

# Pod 생성
$ kubectl create -f nginx-stable.yaml -f nginx-canary.yaml -f mainui-svc.yaml

# 서비스 및 Deploy 생성 확인
$ kubectl describe service mainui-svc
$ kubectl get deployment.apps

# 접속 확인
$ curl <Service IP>:<Service Port>

# 로그 확인
$ kubectl logs deployment.apps nginx-canary

# canary pod 개수 증가 
$ kubectl scale deployment nginx-canary --replicas=3

# 증가된 Pod 개수 확인
$ kubectl describe deployment.apps
profile
React, Node.js, AWS, Git, Github, Github Action, Docker, K8S

0개의 댓글