본문 바로가기

Kubernetes

[Kubernetes] kubernetes Canary Deployment

반응형

Canary Deployment

 - 포드를 배포(업데이트)하는 방법

  1. 블루 그린 업데이트

  2. 카나리 업데이트

  3. 롤링 업데이트

 - Canary 배포

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

카나리 배포 실습

mainui-stable.yaml 실행 후 pod 확인

# 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
        
# kubectl create -f mainui-stable.yaml 
deployment.apps/mainui-stable created

# kubectl get pods
NAME                             READY   STATUS    RESTARTS   AGE
mainui-stable-5b7b6cc49f-85b9z   1/1     Running   0          5s
mainui-stable-5b7b6cc49f-cs5gg   1/1     Running   0          5s

# kubectl get pods --show-labels 
NAME                             READY   STATUS    RESTARTS   AGE   LABELS
mainui-stable-5b7b6cc49f-85b9z   1/1     Running   0          12s   app=mainui,pod-template-hash=5b7b6cc49f,version=stable
mainui-stable-5b7b6cc49f-cs5gg   1/1     Running   0          12s   app=mainui,pod-template-hash=5b7b6cc49f,version=stable

 

카나리 배포 실습을 위해 mainui-stable.yaml 을 실행하여 생성된 pod의 service를 통해 단일 진입점을 만들어준다.

# cat mainui-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: mainui-svc
spec:
  selector:
    app: mainui
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80

# kubectl get service mainui-svc 
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
mainui-svc   ClusterIP   10.103.121.134   <none>        80/TCP    8m30s

# kubectl create -f mainui-service.yaml 
service/mainui-svc created

# kubectl describe service mainui-svc 
Name:              mainui-svc
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          app=mainui
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.103.121.134
IPs:               10.103.121.134
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.36.0.2:80,10.44.0.1:80
Session Affinity:  None
Events:            <none>

 

curl 명령을 통해 정상적으로 호출 되는지 확인

# curl 10.103.121.134
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

 

mainui-canary.yaml 실행 후 pod 및 service 연결 확인

# 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
        
# kubectl create -f mainui-canary.yaml 
deployment.apps/mainui-canary created

# kubectl describe service mainui-svc 
Name:              mainui-svc
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          app=mainui
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.103.121.134
IPs:               10.103.121.134
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.36.0.2:80,10.44.0.1:80,10.44.0.2:80
Session Affinity:  None
Events:            <none>

 

deployment 확인하면 stable, canary 확인이 가능하고 scale 및 delete 가능하고 상황에 맞게 배포 방법 사용 가능

# kubectl get deployments.apps 
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
mainui-canary   1/1     1            1           28s
mainui-stable   2/2     2            2           15m

# kubectl scale deployment mainui-canary --replicas=2
deployment.apps/mainui-canary scaled

# kubectl get deployments.apps 
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
mainui-canary   2/2     2            2           51s
mainui-stable   2/2     2            2           15m

# kubectl get deployments.apps 
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
mainui-canary   2/2     2            2           52s
mainui-stable   2/2     2            2           15m

# kubectl delete deployments.apps mainui-canary 
deployment.apps "mainui-canary" deleted

 

 

[참고]

- https://www.youtube.com/watch?v=u588KXtBoKU

 

반응형

'Kubernetes' 카테고리의 다른 글

[Kubernetes] Secret  (0) 2022.12.21
[Kubernetes] ConfigMap  (0) 2022.12.20
[Kubernetes] Annotation  (0) 2022.12.17
[Kubernetes] kubernetes node label  (0) 2022.12.17
[Kubernetes] kubernetes label 쿠버네티스 레이블  (0) 2022.12.16