Project/Program

[Kubernetes in Google Cloud] Managing Deployments Using Kubernetes Engine

choideu 2023. 5. 6. 15:48

Task 1. Learn about the deployment object

1. explain 명령어 사용: deployment object explain

kubectl explain deployment

2. --recursive 옵션을 사용해 모든 필드를 확인할 수 있음

kubectl explain deployment --recursive

*실습을 진행하면서 explain 명령을 사용하면 배포 개체의 구조를 이해하고 개별 필드의 기능을 파악할 수 있음

 

Task 2. Create a deployment

1. deployments/auth.yaml 업데이트 하기(수정)

vi deployments/auth.yaml

2. 배포 컨테이너 섹션 변경

...
containers:
- name: auth
  image: "kelseyhightower/auth:1.0.0"
...

3. kubectl create 명령: deployment manifest와 일치하는 하나의 Pod가 생성됨

kubectl create -f deployments/auth.yaml

4. 배포 생성 확인

kubectl get deployments

5. deployment 생성 후에 쿠버네티스는 배포를 위한 ReplicaSet을 생성하는데, 아래 명령어로 ReplicaSet이 생성되었는지 확인할 수 있음

kubectl get replicasets

6. Deployment의 일부로 생성된 Pod 확인 가능

*단일 Pod는 ReplicaSet이 생성될 때 쿠버네티스에 의해 생성됨

kubectl get pods

7. kubectl create로 auth service 생성하기

kubectl create -f services/auth.yaml

8. hello deployment를 생성하고 노출하기 and Frontend deployment를 생성하고 노출하기

kubectl create -f deployments/hello.yaml
kubectl create -f services/hello.yaml

kubectl create secret generic tls-certs --from-file tls/
kubectl create configmap nginx-frontend-conf --from-file=nginx/frontend.conf
kubectl create -f deployments/frontend.yaml
kubectl create -f services/frontend.yaml

9. curl으로 통신하기

curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`

+ kubectl scale deployment [NAME] --relicas=n으로 scale up 가능

 

Task 3. Rolling update

Deploymnets는 Rolling Update 메커니즘을 통해 이미지를 새 버전으로 업데이트하는 기능을 지원함

-> 이전 ReplicaSet의 개수를 줄이면서 New ReplicaSet의 개수를 늘리는 업데이트 방식

1. hello deployment 수정하기

kubectl edit deployment hello

-> 에디터에서 저장하면 업데이트된 배포가 클러스터에 저장되고 Kubernetes가 Rolling Update를 시작함

2. 새로운 ReplicaSet

kubectl get replicaset

3. rollout history 확인하기

kubectl rollout history deployment/hello

4. rolling update 중지하기

kubectl rollout pause deployment/hello

5. rollout 현재 상태 확인하기

kubectl rollout status deployment/hello

+ pod에서 직접 확인도 가능

kubectl get pods -o jsonpath --template='{range .items[*]}{.metadata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'

6. rolling update 재개

kubectl rollout resume deployment/hello

7. update 원복하기

kubectl rollout undo deployment/hello

8. roll back history 확인하기

kubectl rollout history deployment/hello

 

Task 4. Canary deployments

일부 사용자를 대상으로 production 환경에서 새 배포를 테스트하려는 때 Canary Deployment를 사용함

-> 소수의 사용자에게 변경 사항을 Release하여 위험을 낮출 수 있음

1. canary deployment 생성하기

kubectl create -f deployments/hello-canary.yaml

Rolling vs Canary vs Blue/Green update

모두 소프트웨어 배포를 최신 버전으로 업데이트하는 방법 중 일부임

  • rolling deployment
    • 이전 버전에서 새 버전으로 서비스를 업데이트하는 방법으로, 이전 버전의 서비스에서 하나씩 새 버전으로 전환하면서 업데이트 수행
    • 전환 중에도 서비스를 계속 사용할 수 있음

-> 서비스를 계속 사용할 수 있는 상태에서 새 버전으로 전환하고자 할 때 유용함

  • Canary deployment
    • 작은 규모의 사용자 그룹에서 새 버전을 배포해 안정성을 테스트 후, 전체 서비스에서 새 버전을 배포하는 방법

-> 안정성 테스트를 위해 일부 사용자 그룹에 새 버전을 배포하고자 할 때 유용함

  • blue/green deployment
    • 전체 서비스의 두 개의 복제본을 유지함
    • 이전 버전을 실행하는 블루 환경과 새 버전을 실행하는 그린 환경이 있음
    • 이전 버전과 새 버전을 모두 유지하여 새로운 버전의 안정성 테스트와 문제 발생시 이전 버전으로 쉽게 전환이 가능