본문 바로가기

Container/Kubernetes

[K8S] Canary Deployment

파드 배포하는 방법

  • 블루 그린 업데이트
  • 카나리 업데이트
  • 롤링 업데이트 : 서비스 중단 없이 하나씩 업데이트

Canary 배포

  • 기존 버전을 유지한 채로 일부 버전만 신규 버전으로 올려서 신규 버전에 버그나 이상이 없는 지 확인.

레이블을 이용한 카나리 배포

# 블루 생성
[master ~]$cat mainui-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
[master ~]$kubectl create -f mainui-stable.yaml 
deployment.apps/mainui-stable created
[master ~]$kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
mainui-stable-d8c4c64d7-jswh6   1/1     Running   0          7s
mainui-stable-d8c4c64d7-rlcl5   1/1     Running   0          7s
[master ~]$kubectl get pods --show-labels
NAME                            READY   STATUS    RESTARTS   AGE   LABELS
mainui-stable-d8c4c64d7-jswh6   1/1     Running   0          16s   app=mainui,pod-template-hash=d8c4c64d7,version=stable
mainui-stable-d8c4c64d7-rlcl5   1/1     Running   0          16s   app=mainui,pod-template-hash=d8c4c64d7,version=stable

# 서비스 단일 진입점 생성
## app가 mainui인 것들을 하나의 단일 진입점으로 묶기.(Service)
[master ~]$cat mainui-service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: mainui-svc
spec:
  selector:
    app: mainui
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
    
[master ~]$kubectl create -f mainui-service.yaml 
service/mainui-svc created

[master ~]$kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.8.0.1     <none>        443/TCP   67s
mainui-svc   ClusterIP   10.8.1.111   <none>        80/TCP    27s
# 10.8.1.111으로 접속하면 1.14버전 2개가 나란히 실행됨

[master ~]$kubectl describe service mainui-svc
Name:              mainui-svc
Namespace:         default
Labels:            <none>
Annotations:       cloud.google.com/neg: {"ingress":true}
Selector:          app=mainui
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.8.1.111
IPs:               10.8.1.111
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.4.0.40:80,10.4.2.18:80
Session Affinity:  None
Events:            <none>

[master ~]$curl 10.8.1.111

# 그린 (Canary) 버전 생성
[master ~]$cat mainui-canary.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mainui-canary
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mainui
      version: canary
  template:
    metadata:
      labels:
        app: mainui
        version: canary
    spec:
      containers:
      - name: mainui
        image: nginx:1.15
        ports:
        - containerPort: 80
        
[master ~]$kubectl create -f mainui-canary.yaml 
deployment.apps/mainui-canary created

[master ~]$kubectl describe service mainui-svc
Name:              mainui-svc
Namespace:         default
Labels:            <none>
Annotations:       cloud.google.com/neg: {"ingress":true}
Selector:          app=mainui
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.8.1.111
IPs:               10.8.1.111
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.4.0.40:80,10.4.0.41:80,10.4.2.18:80 # 3개의 Pod 연결된 것 확인
Session Affinity:  None
Events:            <none>

[master ~]$kubectl get deployments
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
mainui-canary   1/1     1            1           73s # 1개 배포되어있음
mainui-stable   2/2     2            2           5m16s

# canary 늘리기
[master ~]$kubectl scale deployment mainui-canary --replicas=2
deployment.apps/mainui-canary scaled
[master ~]$kubectl get deployments
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
mainui-canary   1/2     2            1           2m8s 
mainui-stable   2/2     2            2           6m11s
반응형

'Container > Kubernetes' 카테고리의 다른 글

[K8S] Affinity & antiAffinity  (0) 2024.03.25
[K8S] Secret  (0) 2024.03.20
[K8S] Annotation  (0) 2024.03.17
[K8S] Node Label & Selector  (0) 2024.03.17
[K8S] 쿠버네티스 레이블  (0) 2024.03.17