Room9

CKAD - Application Deployment (Blue/Green, Canary) 본문

Kubernetes

CKAD - Application Deployment (Blue/Green, Canary)

Room9_ 2022. 1. 24. 10:54

배포전략

  • Blue/Green
  • Canary
  • RollingUpdate
  • Recreate

Blue / Green

이전버전을 블루, 새로운 버전을 그린으로 지칭하며 기존 트래픽은 Blue가 처리하고 있는 와중에 Green의 새로운 버전 테스트가 완료되면 Blue로 처리되던 트래픽을 Green으로 전환하여 버전을 변경한다.

Kubernetes에서 Blue / Green

  • blue-deployment ( labels - version:v1 ) + Service : 기존버전
  • green-deployment ( labels - version:v2 ) : 새로운 버전
  • Service의 Selector를 기존 version:v1 에서 version:v2 로 변경
Blue / Green 배포를 진행할 때의 단점으로는 Blue버전(구버전))과 Green 버전(신버전)을 동시에 유지해야함으로 리소스 사용량이 2배로 든다는 단점이 있다.

Canary

기존 버전을 그대로 유지하면서 적당한 수준 또는 일정한 비율의 새로운 버전의 어플리케이션을 동시에 운영한다. 대부분의 트래픽은 기존 버전이 처리하고 새로운 버전으로 처리하면서 새로운 버전의 기능에 대해 테스트를 진행 할 수 있다. 새로운 버전이 정상적으로 동작한다면 기존 버전을 하나씩 제거하며, 새로운 버전으로 교체가 완료 된다.

Kubernete에서 Canary

  • origin-deployment (labels - version :v1, replicas - 5 ) + Service
  • canary-deployment (labels -version :v2, replicas - 1 )
  • 두 Deployment로 모두 트래픽을 보내기 위해 기존 레이블이 아닌 공통의 레이블을 생성한다 (labels - app: frontend)
  • origin-deployment (labels - version :v1, app:frontend, replicas - 5 ) + Service
  • canary-deployment (labels -version :v2, app:frontend, replicas - 1 )
  • Service의 selector 에 설정된 version이 아닌 새로 생성한 app:frontend로 변경하여 양쪽으로 트래픽을 보낸다.
  • 레플리카 수의 따라 비율은 origin-deployment : canary-deployment = 5 : 1
여기서 비율은 레플리카 수에 따른 비율로 책정되기 때문에, 예를들어 99퍼센트의 기존 서비스와 1퍼센트의 새로운 서비스를 이용하여 배포를 진행하겠다고 하면 99개의 기존 파드와 1개의 새로운 파드를 구성하여야 비율을 맞출 수 있다. 총 100개의 파드가 필요함
Istio를 사용하면 파드의 갯수에 제약 받지 않고 비율을 조절하여 진행 할 수 있다.

KodeKloud

Q1. A deployment has been created in the default namespace. What is the deployment strategy used for this deployment?

root@controlplane:~# kubectl describe deployments.apps frontend
Name:                   frontend
Namespace:              default
CreationTimestamp:      Mon, 24 Jan 2022 01:05:20 +0000
Labels:                 app=myapp
                        tier=frontend
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=frontend
Replicas:               5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType:           RollingUpdate

 > RollingUpdate


Q2. The deployment called frontend app is exposed on the NodePort via a service. Identify the name of this service.

root@controlplane:~# kubectl get svc
NAME               TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
frontend-service   NodePort    10.99.168.29   <none>        8080:30080/TCP   3m17s
kubernetes         ClusterIP   10.96.0.1      <none>        443/TCP          14m

 > frontend-service


Q3. What is the selector used by this service? Inspect the service called frontend-service.

root@controlplane:~# kubectl describe svc frontend-service 
Name:                     frontend-service
Namespace:                default
Labels:                   app=myapp
Annotations:              <none>
Selector:                 app=frontend
Type:                     NodePort
IP Families:              <none>
IP:                       10.99.168.29
IPs:                      10.99.168.29
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30080/TCP
Endpoints:                10.244.0.4:8080,10.244.0.5:8080,10.244.0.6:8080 + 2 more...
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

 > app=frontend


Q4. Check out the web application using the Webapp link above your terminal.


Q5. A new deployment called frontend-v2 has been created in the default namespace using the image kodekloud/webapp-color:v2. This deployment will be used to test a newer version of the same app.

Configure the deployment in such a way that the service called frontend-service routes less than 20% of traffic to the new deployment. Do not increase the replicas of the frontend deployment.

root@controlplane:~# kubectl describe deployments.apps frontend-v2 
Name:                   frontend-v2
Namespace:              default
CreationTimestamp:      Mon, 24 Jan 2022 01:32:06 +0000
Labels:                 app=myapp
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=frontend
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=frontend
           version=v2
  Containers:
   webapp-color:
    Image:        kodekloud/webapp-color:v2
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   frontend-v2-76fb9546d9 (2/2 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  102s  deployment-controller  Scaled up replica set frontend-v2-76fb9546d9 to 2

 > 기존 frontend deployment는 5개의 레플리카로 구성되어 있고 새로운 frontend-v2 deployment는 2개의 레플리카로 구성되어

    5:2 비율로 구성되어 있음 약 29% 비율로 트래픽을 나누어 처리중, 문제에서 20%미만으로 구성하라고 하였으며, 기존 frontend의 레      플리카 갯수 조정이 없어야 함으로 frontend-v2의 레플리카를 1로 변경해준다

root@controlplane:~# kubectl scale deployment frontend-v2 --replicas=1
deployment.apps/frontend-v2 scaled
root@controlplane:~# kubectl get deployments.apps 
NAME          READY   UP-TO-DATE   AVAILABLE   AGE
frontend      5/5     5            5           6m39s
frontend-v2   1/1     1            1           4m14s

Q6. Check out the new version of the web application using the Webapp link above your terminal. You may need to refresh it multiple times to see the new version.


Q7. We have now established that the new version v2 of the application is working as expected. We can now safely redirect all users to the v2 version.

 > OK


Q8. Scale down the v1 version of the apps to 0 replicas and scale up the new(v2) version to 5 replicas.

root@controlplane:~# kubectl scale deployment frontend-v2 --replicas=5
deployment.apps/frontend-v2 scaled
root@controlplane:~# kubectl scale deployment frontend --replicas=0
deployment.apps/frontend scaled
root@controlplane:~# kubectl get deployments.apps                  
NAME          READY   UP-TO-DATE   AVAILABLE   AGE
frontend      0/0     0            0           21m
frontend-v2   5/5     5            5           18m

Q9. Now delete the deployment called frontend completely.

root@controlplane:~# kubectl delete deployments.apps frontend
deployment.apps "frontend" deleted
root@controlplane:~# kubectl get deployments.apps 
NAME          READY   UP-TO-DATE   AVAILABLE   AGE
frontend-v2   5/5     5            5           19m

Q10. You can now reload the Webapp tab to validate that all user traffic now uses the v2 version of the app.

 > 이제 v2로만 트래픽 처리를 한다.


 

Comments