brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Mar 10. 2022

116.디플로이먼트 롤링 업데이트 및 롤백 6/8

디플로이먼트 롤링 업데이트 및 롤백  6/20


<1> 디플로이먼트 생성

<2> 디플로이먼트 생성 시 record 옵션 사용

<3> 버전 (롤리) 업데이트 실행 및 확인 :

<4> 버전 롤백 : 기존 v1.14 → v1.2



<1>  디플로이먼트 생성



1

cat  << EOF > deployment-nginx-1.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: deployment-nginx

spec:

  replicas: 3

  selector:

    matchLabels:

      app: cndk-nginx-pods

  template:

    metadata:

      name: cndk-nginx-pod

      labels:

        app: cndk-nginx-pods

    spec:

      containers:

      - name: nginx

        image: nginx:1.11

EOF





<2>  디플로이먼트 생성 시 record 옵션 사용



1

# 생성 시 --record 옵션을 추가

kubectl apply -f deployment-nginx-1.yaml --record


2

# 파드 정보 확인

[root@test11 ~]# kubectl apply -f deployment-nginx-1.yaml --record

Flag --record has been deprecated, --record will be removed in the future

deployment.apps/deployment-nginx created


[root@test11 ~]# kubectl get pod -o wide

NAME                                READY   STATUS              RESTARTS   AGE   IP       NODE                    NOMINATED NODE   READINESS GATES

deployment-nginx-77b4cbf48d-8p8s6   0/1     ContainerCreating   0          11s   <none>   game1-nodepool-w-11gc   <none>           <none>

deployment-nginx-77b4cbf48d-wrt49   0/1     ContainerCreating   0          11s   <none>   game1-nodepool-w-11gc   <none>           <none>

deployment-nginx-77b4cbf48d-x8xh5   0/1     ContainerCreating   0          11s   <none>   game1-nodepool-w-11gc   <none>           <none>

[root@test11 ~]#



3

# 파드 이미지 확인

[root@test11 ~]# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.11

    - image: nginx:1.11

    - image: nginx:1.11



4

# --record 옵션의 정보 확인

kubectl rollout history deployment deployment-nginx


[root@test11 ~]# kubectl rollout history deployment deployment-nginx

deployment.apps/deployment-nginx

REVISION  CHANGE-CAUSE

1         kubectl apply --kubeconfig=/root/kubeconfig.yml --filename=deployment-nginx-1.yaml --record=true






<3> 버전 (롤링) 업데이트 실행 및 확인 :



기존 v1.11 → 업데이트 v1.12 ⇒ 파드 종료와 생성이 어떤 순서대로 되는지 확인!


1

# 터미널2

while true; do kubectl rollout status deployment deployment-nginx && echo "--------------" && date; sleep 1; done


2

# v1.12 로 버전 업데이트 실행

kubectl set image deployment deployment-nginx nginx=nginx:1.12 --record && kubectl get pod -w

kubectl get pod -o yaml | grep "image: nginx"


[root@test11 ~]# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.12

    - image: nginx:1.12

    - image: nginx:1.1


3

# 한번 더 버전 업데이트 

kubectl set image deployment deployment-nginx nginx=nginx:1.13 --record && kubectl get pod -w

kubectl get pod -o yaml | grep "image: nginx"


4

# 마지막으로 한번 더!

kubectl set image deployment deployment-nginx nginx=nginx:1.14 --record && kubectl get pod -w

kubectl get pod -o yaml | grep "image: nginx"


5

# 버전 업데이트 히스토리 확인

kubectl rollout history deployment deployment-nginx


[root@test11 ~]# kubectl rollout history deployment deployment-nginx

deployment.apps/deployment-nginx

REVISION  CHANGE-CAUSE

1         kubectl apply --kubeconfig=/root/kubeconfig.yml --filename=deployment-nginx-1.yaml --record=true

2         kubectl set image deployment deployment-nginx nginx=nginx:1.12 --kubeconfig=/root/kubeconfig.yml --record=true

3         kubectl set image deployment deployment-nginx nginx=nginx:1.13 --kubeconfig=/root/kubeconfig.yml --record=true

4         kubectl set image deployment deployment-nginx nginx=nginx:1.14 --kubeconfig=/root/kubeconfig.yml --record=true




<4> 버전 롤백 : 기존 v1.14 → v1.2


1

# 리비전 2로 버전 롤백

kubectl rollout undo deployment deployment-nginx --to-revision=2

kubectl get pod -o yaml | grep "image: nginx"


[root@test11 ~]# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.14

    - image: nginx:1.14

    - image: nginx:1.14

    - image: nginx:1.12

    - image: nginx:1.12

    - image: nginx:1.12


[root@test11 ~]# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.12

    - image: nginx:1.12

    - image: nginx:1.12



2

# 어떻게 버전별 롤백이 가능한걸까? 레플리카셋 정보(기록)을 가지고 있으며, Labels 로 구별되어 있다!


kubectl get replicasets.apps --show-labels


[root@test11 ~]# kubectl get replicasets.apps --show-labels

NAME                          DESIRED   CURRENT   READY   AGE     LABELS

deployment-nginx-5cbcc59b4c   0         0         0       94s     app=cndk-nginx-pods,pod-template-hash=5cbcc59b4c

deployment-nginx-67cc8cd4f4   0         0         0       111s    app=cndk-nginx-pods,pod-template-hash=67cc8cd4f4

deployment-nginx-77b4cbf48d   0         0         0       5m29s   app=cndk-nginx-pods,pod-template-hash=77b4cbf48d

deployment-nginx-78bc6dfdf7   3         3         3       3m8s    app=cndk-nginx-pods,pod-template-hash=78bc6dfdf7



3

# 디플로이먼트의 상세 정보 확인

kubectl describe deployments.apps deployment-nginx



[root@test11 ~]# kubectl describe deployments.apps deployment-nginx

Name:                   deployment-nginx

Namespace:              default

CreationTimestamp:      Thu, 10 Mar 2022 22:48:58 +0900

Labels:                 <none>

Annotations:            deployment.kubernetes.io/revision: 5

                        kubernetes.io/change-cause: kubectl set image deployment deployment-nginx nginx=nginx:1.12 --kubeconfig=/root/kubeconfig.yml --record=true

Selector:               app=cndk-nginx-pods

Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable

StrategyType:           RollingUpdate

MinReadySeconds:        0

RollingUpdateStrategy:  25% max unavailable, 25% max surge

Pod Template:

  Labels:  app=cndk-nginx-pods

  Containers:

   nginx:

    Image:        nginx:1.12

    Port:         <none>

    Host Port:    <none>

    Environment:  <none>

    Mounts:       <none>

  Volumes:        <none>

Conditions:

  Type           Status  Reason

  ----           ------  ------

  Available      True    MinimumReplicasAvailable

  Progressing    True    NewReplicaSetAvailable

OldReplicaSets:  <none>

NewReplicaSet:   deployment-nginx-78bc6dfdf7 (3/3 replicas created)

Events:

  Type    Reason             Age                  From                   Message

  ----    ------             ----                 ----                   -------

  Normal  ScalingReplicaSet  5m51s                deployment-controller  Scaled up replica set deployment-nginx-77b4cbf48d to 3

  Normal  ScalingReplicaSet  3m30s                deployment-controller  Scaled up replica set deployment-nginx-78bc6dfdf7 to 1

  Normal  ScalingReplicaSet  3m19s                deployment-controller  Scaled down replica set deployment-nginx-77b4cbf48d to 2

  Normal  ScalingReplicaSet  3m17s                deployment-controller  Scaled down replica set deployment-nginx-77b4cbf48d to 1

  Normal  ScalingReplicaSet  3m17s                deployment-controller  Scaled up replica set deployment-nginx-78bc6dfdf7 to 3

  Normal  ScalingReplicaSet  3m15s                deployment-controller  Scaled down replica set deployment-nginx-77b4cbf48d to 0

  Normal  ScalingReplicaSet  2m13s                deployment-controller  Scaled up replica set deployment-nginx-67cc8cd4f4 to 1

  Normal  ScalingReplicaSet  2m4s                 deployment-controller  Scaled down replica set deployment-nginx-78bc6dfdf7 to 2

  Normal  ScalingReplicaSet  55s (x2 over 3m19s)  deployment-controller  Scaled up replica set deployment-nginx-78bc6dfdf7 to 2

  Normal  ScalingReplicaSet  51s (x15 over 2m4s)  deployment-controller  (combined from similar events): Scaled down replica set deployment-nginx-5cbcc59b4c to 0

[root@test11 ~]#



4

[root@test11 ~]# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.12

    - image: nginx:1.12

    - image: nginx:1.12


5

# 다음 실습을 위해 삭제

kubectl delete deployments.apps --all


[root@test11 ~]# k get pods

No resources found in default namespace.



다음 과정

https://brunch.co.kr/@topasvga/2238


https://brunch.co.kr/@topasvga/2240


감사합니다.


브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari