brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jan 11. 2022

네이버5탄-롤링 업데이트와 원복 -5/9

참고 

롤링 업데이트 - 레코드 , record

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




순차적 업데이트하는 롤링 업데이트하고,  원복 해보자


<1> 순차적 업데이트 롤링 업데이트

<2> 원복 

<3> 참고 :  blue / green  업데이트 ,  카나리 업데이트  




<1> 순차적 업데이트 롤링 업데이트


1

cat << EOF > roll-nginx.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

  name: roll-nginx

spec:

  replicas: 3

  selector:

    matchLabels:

      app: nginx-pod

  template:

    metadata:

      name: nginx-pod

      labels:

        app: nginx-pod

    spec:

      containers:

      - name: nginx

        image: nginx:1.15.12

EOF




2

kubectl apply -f  roll-nginx.yaml --record


3

확인

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


(admin-k8s:default) root@k8s-m:~# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12


4

히스토리 확인

kubectl rollout history deployment roll-nginx


(admin-k8s:default) root@k8s-m:~# kubectl rollout history deployment roll-nginx

deployment.apps/roll-nginx

REVISION  CHANGE-CAUSE

1         kubectl apply --filename=roll-nginx.yaml --record=true



5

배포한 파드 정보 확인 ?


k get pods -o=custom-columns=NAME:.metadata.name,STATUS:,NODE:.spec.nodeName


(admin-k8s:default) root@k8s-m:~# k get pods -o=custom-columns=NAME:.metadata.name,STATUS:,NODE:.spec.nodeName

NAME                          STATUS   NODE

roll-nginx-86965779d6-2prg2   <none>   k8s-w1

roll-nginx-86965779d6-98dmj   <none>   k8s-w2

roll-nginx-86965779d6-dn454   <none>   k8s-w1



6

1.16 으로 변경해보기


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

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



하나씩 순차적으로 지우고 생성 된다.


(admin-k8s:default) root@k8s-m:~# kubectl set image deployment roll-nginx nginx=nginx:1.16 --record && kubectl get pod -w

deployment.apps/roll-nginx image updated

NAME                          READY   STATUS              RESTARTS   AGE

roll-nginx-864cb98d98-4vlxp   0/1     ContainerCreating   0          0s

roll-nginx-86965779d6-2prg2   1/1     Running             0          9m50s

roll-nginx-86965779d6-98dmj   1/1     Running             0          9m50s

roll-nginx-86965779d6-dn454   1/1     Running             0          9m50s

roll-nginx-864cb98d98-4vlxp   0/1     ContainerCreating   0          1s



(admin-k8s:default) root@k8s-m:~# kubectget pod -o yaml | grep "image: nginx"-w

    - image: nginx:1.16

    - image: nginx:1.16

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12



(admin-k8s:default) root@k8s-m:~# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.16

    - image: nginx:1.16

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12



(admin-k8s:default) root@k8s-m:~# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.16

      image: nginx:1.16

    - image: nginx:1.16

      image: nginx:1.16

    - image: nginx:1.16

      image: nginx:1.16





7

pod 확인

하나씩 순차적으로 지우고 새로 생성 되었다.


k get pod -w


(admin-k8s:default) root@k8s-m:~# k get pod -w

NAME                          READY   STATUS    RESTARTS   AGE

roll-nginx-864cb98d98-4vlxp   1/1     Running   0          2m41s

roll-nginx-864cb98d98-g8mw9   1/1     Running   0          2m9s

roll-nginx-864cb98d98-gghtq   1/1     Running   0          2m25s



8

히스토리 확인


kubectl rollout history deployment roll-nginx


(admin-k8s:default) root@k8s-m:~# kubectl rollout history deployment roll-nginx

deployment.apps/roll-nginx

REVISION  CHANGE-CAUSE

1         kubectl apply --filename=roll-nginx.yaml --record=true

2         kubectl set image deployment roll-nginx nginx=nginx:1.16 --record=true



9

라벨이 구분되어 있어 롤백이 가능하다.


kubectl get replicasets.apps --show-labels


(admin-k8s:default) root@k8s-m:~#  kubectl get replicasets.apps --show-labels

NAME                    DESIRED   CURRENT   READY   AGE     LABELS

roll-nginx-864cb98d98   3         3         3       7m25s   app=nginx-pod,pod-template-hash=864cb98d98

roll-nginx-86965779d6   0         0         0       17m     app=nginx-pod,pod-template-hash=86965779d6




10

ssh를  하나 더 띠워 모니터링 하자~


모니터링

watch -d 'kubectl get pods,rs,deploy -o wide'  





11

상세 확인

문제가 있으면 여기에 나온다~


kubectl describe deployments.apps deployment-nginx




12

1.17 로 업그레이드

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


변경 확인

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


(admin-k8s:default) root@k8s-m:~# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.17

      image: nginx:1.17

    - image: nginx:1.17

      image: nginx:1.17

    - image: nginx:1.17

      image: nginx:1.17


watch -d 'kubectl get pods,rs,deploy -o wide'



히스토리 확인

kubectl rollout history deployment roll-nginx


(admin-k8s:default) root@k8s-m:~# kubectl rollout history deployment roll-nginx

deployment.apps/roll-nginx

REVISION  CHANGE-CAUSE

1         kubectl apply --filename=roll-nginx.yaml --record=true

2         kubectl set image deployment roll-nginx nginx=nginx:1.16 --record=true

3         kubectl set image deployment roll-nginx nginx=nginx:1.17 --record=true





<2> 원복 


바로 앞으로 원복  ??


k rollout undo deployment roll-nginx


(admin-k8s:default) root@k8s-m:~# k rollout undo deployment roll-nginx

deployment.apps/roll-nginx rolled back


확인

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


(admin-k8s:default) root@k8s-m:~# kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.16

      image: nginx:1.16

    - image: nginx:1.16

      image: nginx:1.16

    - image: nginx:1.16

      image: nginx:1.16




2

특정 시점으로 원복  ??


히스토리 확인

히스토리  4로 변경됨

kubectl rollout history deployment roll-nginx


(admin-k8s:default) root@k8s-m:~# kubectl rollout history deployment roll-nginx

deployment.apps/roll-nginx

REVISION  CHANGE-CAUSE

1         kubectl apply --filename=roll-nginx.yaml --record=true

3         kubectl set image deployment roll-nginx nginx=nginx:1.17 --record=true

4         kubectl set image deployment roll-nginx nginx=nginx:1.16 --record=true



특정 시점으로 원복 ?

k rollout undo deployment roll-nginx --to-revision=1


(admin-k8s:default) root@k8s-m:~# k rollout undo deployment roll-nginx --to-revision=1

deployment.apps/roll-nginx rolled back



3

확인?

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


(admin-k8s:default) root@k8s-m:~#  kubectl get pod -o yaml | grep "image: nginx"

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12

    - image: nginx:1.15.12

      image: nginx:1.15.12



4

삭제


k delete deploy roll-nginx





<3> 참고 :  blue / green  업데이트 ,  카나리 업데이트  


1

blue / green  업데이트

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


2

카나리 업데이트

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




다음 공부는 

82. 외부로 노출하는 nodeport서비스


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


감사합니다.

매거진의 이전글 네이버5탄-쿠버네티스 오브젝트 -4/9

작품 선택

키워드 선택 0 / 3 0

댓글여부

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