🐤 Kubernetes Canary Deployment 완전 정리
2026. 2. 21. 20:49ㆍk8s
Canary Deployment는
새로운 버전을 일부 사용자에게만 먼저 배포해서
문제 여부를 확인한 뒤 점진적으로 확장하는 배포 전략
이다.
이름은 과거 광산에서 유독가스 감지를 위해
카나리 새를 먼저 들여보낸 것에서 유래했다.
📌 왜 Canary가 필요한가?
일반 Rolling Update는:
- 기존 Pod를 점진적으로 교체
- 전체 트래픽이 동시에 새 버전으로 이동
하지만 Canary는:
- 일부 트래픽만 새 버전으로 전달
- 문제 발생 시 영향 최소화
📊 Rolling Update vs Canary 비교
| 구분 | Rolling Update | Canary |
|---|---|---|
| 교체 방식 | 전체 점진 교체 | 일부만 먼저 배포 |
| 트래픽 제어 | 없음 | 가능 |
| 리스크 | 중간 | 낮음 |
| 복잡도 | 낮음 | 상대적으로 높음 |
🏗 Kubernetes에서 Canary 구현 방식
Kubernetes에는 “Canary”라는 리소스는 없다.
대신 다음 방식으로 구현한다:
방법 1️⃣ Deployment 2개 + Service 1개
- 기존 Deployment (stable)
- 새로운 Deployment (canary)
- Service는 두 Deployment 모두 선택
📦 예시 구성
🔹 Stable Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-stable
spec:
replicas: 9
selector:
matchLabels:
app: nginx
version: stable
template:
metadata:
labels:
app: nginx
version: stable
spec:
containers:
- name: nginx
image: nginx:1.18.0
🔹 Canary Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-canary
spec:
replicas: 1
selector:
matchLabels:
app: nginx
version: canary
template:
metadata:
labels:
app: nginx
version: canary
spec:
containers:
- name: nginx
image: nginx:1.24.0
🔹 Service
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- port: 80
targetPort: 80
🔎 트래픽 비율은 어떻게 결정될까?
Service는 label 기반으로 Pod를 선택한다.
위 구성에서는:
- stable: 9개
- canary: 1개
총 10개 Pod 중 1개가 canary → 약 10% 트래픽
즉,
replica 수로 비율을 조절한다.
📈 Canary 확장 단계
1️⃣ 1개 canary Pod 배포 (10%)
2️⃣ 모니터링
3️⃣ 3개로 확장 (30%)
4️⃣ 이상 없으면 stable 제거 후 full 전환
🛑 문제 발생 시
canary Deployment를 0으로 줄이면 된다.
kubectl scale deploy/nginx-canary --replicas=0
즉시 트래픽 차단 가능.
🚀 고급 방식 (Ingress 기반)
Ingress Controller 사용 시:
- 특정 header
- 특정 user group
- 특정 비율
로 트래픽을 정교하게 제어 가능
예: NGINX Ingress annotation 사용
🎯 Canary의 핵심 포인트
✔ 기존 버전 유지
✔ 일부만 새 버전 적용
✔ 점진적 확장
✔ 빠른 차단 가능
📌 Canary vs Blue-Green
| 구분 | Canary | Blue-Green |
|---|---|---|
| 트래픽 | 점진적 분할 | 전체 전환 |
| 배포 단계 | 여러 단계 | 1회 전환 |
| 위험도 | 낮음 | 중간 |
🏁 한 줄 정리
Canary Deployment는
새 버전을 일부 트래픽에 먼저 적용하고
문제가 없으면 점진적으로 확장하는 안전한 배포 전략이다.
'k8s' 카테고리의 다른 글
| 📦 Kubernetes LimitRange 완전 정리 (0) | 2026.02.22 |
|---|---|
| 🔐 Kubernetes securityContext 완전 정리 (0) | 2026.02.22 |
| 🔁 Kubernetes Deployment Rollout 완전 정리 (0) | 2026.02.21 |
| 🔁 Kubernetes Deployment에서 ReplicaSet이 여러 개 보이는 이유 (0) | 2026.02.21 |
| 🏷 Kubernetes Deployment에서 Label로 엮이는 구조 이해하기 (0) | 2026.02.21 |