클라우드/Kubernetes

[쿠버네티스] 파드 업그레이드 / 복구

세브웁스 2022. 10. 21. 16:32
반응형

이론

record 옵션

  • 배포한 정보의 히스토리 기록
  • kubectl apply -f ~.yaml --record

rollout

  • history : 기록된 히스토리 확인
    kubectl rollout history ~
  • undo : 이전 버전으로 상태 되돌리기
    kubectl rollout undo ~

describe

  • 상태 자세히 묘사
  • kubectl describe ~

실습

실습과정

업데이트 및 복구 과정


버전 업데이이트된 파드 배포 ( nginx 1.15.12 버전 )

[root@m-k8s ~]# kubectl apply -f ~/_Book_k8sInfra/ch3/3.2.10/rollout-nginx.yaml --record
deployment.apps/rollout-nginx created

 

기록된 히스토리 확인

[root@m-k8s ~]# kubectl rollout history deployment rollout-nginx
deployment.apps/rollout-nginx
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=/root/_Book_k8sInfra/ch3/3.2.10/rollout-nginx.yaml --record=true

 

배포된 파드의 정보 확인

[root@m-k8s ~]# kubectl get pods -o=custom-columns=NAME:.metadata.name,IP:.status.podIP,STATUS:.status.phase,NODE:.spec.nodeName
NAME                             IP               STATUS    NODE
rollout-nginx-64dd56c7b5-cs9n9   172.16.221.143   Running   w1-k8s
rollout-nginx-64dd56c7b5-h52c2   172.16.103.143   Running   w2-k8s
rollout-nginx-64dd56c7b5-kpqld   172.16.132.11    Running   w3-k8s

 

배포된 파드에 속해있는 nginx 컨테이너 버전 확인 ( 1.15.12 버전 확인 )

[root@m-k8s ~]# curl -I --silent 172.16.103.143 | grep Server
Server: nginx/1.15.12

 

배포된 파드의 nginx 버전 업데이트 및 파드 상태 확인 ( IP 바뀜 )

[root@m-k8s ~]# kubectl set image deployment rollout-nginx nginx=nginx:1.16.0 --record
deployment.apps/rollout-nginx image updated

[root@m-k8s ~]# kubectl get pods -o=custom-columns=NAME:.metadata.name,IP:.status.podIP,STATUS:.status.phase,NODE:.spec.nodeName
NAME                             IP               STATUS    NODE
rollout-nginx-8566d57f75-4cl8t   172.16.103.144   Running   w2-k8s
rollout-nginx-8566d57f75-9rm7s   172.16.132.12    Running   w3-k8s
rollout-nginx-8566d57f75-hnj76   172.16.221.144   Running   w1-k8s

 

디플로이먼트 상태 확인

[root@m-k8s ~]# kubectl rollout status deployment rollout-nginx
deployment "rollout-nginx" successfully rolled out

 

rollout-nginx에 적용된 명령 기록 확인

[root@m-k8s ~]# kubectl rollout history deployment rollout-nginx
deployment.apps/rollout-nginx
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=/root/_Book_k8sInfra/ch3/3.2.10/rollout-nginx.yaml --record=true
2         kubectl set image deployment rollout-nginx nginx=nginx:1.16.0 --record=true

 

업데이트가 정상적으로 이루어졌는지 확인

[root@m-k8s ~]# curl -I --silent 172.16.132.12 | grep Server
Server: nginx/1.16.0

업데이트 실패 시 파드 복구하기

[root@m-k8s ~]# kubectl set image deployment rollout-nginx nginx=nginx:1.17.24 --record
deployment.apps/rollout-nginx image updated

[root@m-k8s ~]# kubectl get pods -o=custom-columns=NAME:.metadata.name,IP:.status.podIP,STATUS:.status.phase,NODE:.spec.nodeName
NAME                             IP               STATUS    NODE
rollout-nginx-8566d57f75-4cl8t   172.16.103.144   Running   w2-k8s
rollout-nginx-8566d57f75-9rm7s   172.16.132.12    Running   w3-k8s
rollout-nginx-8566d57f75-hnj76   172.16.221.144   Running   w1-k8s
rollout-nginx-cb7dd7f4b-lv9bq    172.16.221.145   Pending   w1-k8s

 

배포하는 단계에서 대기 중으로 진행되지 않음.

[root@m-k8s ~]# kubectl rollout status deployment rollout-nginx
Waiting for deployment "rollout-nginx" rollout to finish: 1 out of 3 new replicas have been updated...
^C

 

describe 명령으로 문제점 더 자세히 보기

(밑에서 4번째 줄에 NewReplicaSet란에서 멈춰있는 것 확인 )

[root@m-k8s ~]# kubectl describe deployment rollout-nginx
Name:                   rollout-nginx
Namespace:              default
CreationTimestamp:      Fri, 21 Oct 2022 13:48:31 +0900
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 3
                        kubernetes.io/change-cause: kubectl set image deployment rollout-nginx nginx=nginx:1.17.24 --record=true
Selector:               app=nginx
Replicas:               3 desired | 1 updated | 4 total | 3 available | 1 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.17.24
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    ReplicaSetUpdated
OldReplicaSets:  rollout-nginx-8566d57f75 (3/3 replicas created)
NewReplicaSet:   rollout-nginx-cb7dd7f4b (1/1 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  7m26s  deployment-controller  Scaled up replica set rollout-nginx-cb7dd7f4b to 1

 

history 확인

[root@m-k8s ~]# kubectl rollout history deployment rollout-nginx
deployment.apps/rollout-nginx
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=/root/_Book_k8sInfra/ch3/3.2.10/rollout-nginx.yaml --record=true
2         kubectl set image deployment rollout-nginx nginx=nginx:1.16.0 --record=true
3         kubectl set image deployment rollout-nginx nginx=nginx:1.17.24 --record=true

 

rollout undo로 되돌리기

[root@m-k8s ~]# kubectl rollout undo deployment rollout-nginx
deployment.apps/rollout-nginx rolled back
[root@m-k8s ~]# kubectl get pods -o=custom-columns=NAME:.metadata.name,IP:.status.podIP,STATUS:.status.phase,NODE:.spec.nodeName
NAME                             IP               STATUS    NODE
rollout-nginx-8566d57f75-4cl8t   172.16.103.144   Running   w2-k8s
rollout-nginx-8566d57f75-9rm7s   172.16.132.12    Running   w3-k8s
rollout-nginx-8566d57f75-hnj76   172.16.221.144   Running   w1-k8s

 

history 확인

[root@m-k8s ~]# kubectl rollout history deployment rollout-nginx
deployment.apps/rollout-nginx
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=/root/_Book_k8sInfra/ch3/3.2.10/rollout-nginx.yaml --record=true
3         kubectl set image deployment rollout-nginx nginx=nginx:1.17.24 --record=true
4         kubectl set image deployment rollout-nginx nginx=nginx:1.16.0 --record=true

 

정상 확인

[root@m-k8s ~]# curl -I --silent 172.16.132.12 | grep Server
Server: nginx/1.16.0

[root@m-k8s ~]# kubectl rollout status deployment rollout-nginx
deployment "rollout-nginx" successfully rolled out

 

describe로 세부적으로 점검

[root@m-k8s ~]# kubectl describe deployment rollout-nginx
Name:                   rollout-nginx
Namespace:              default
CreationTimestamp:      Fri, 21 Oct 2022 13:48:31 +0900
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 4
                        kubernetes.io/change-cause: kubectl set image deployment rollout-nginx nginx=nginx:1.16.0 --record=true
Selector:               app=nginx
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=nginx
  Containers:
   nginx:
    Image:        nginx:1.16.0
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   rollout-nginx-8566d57f75 (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  11m   deployment-controller  Scaled up replica set rollout-nginx-cb7dd7f4b to 1
  Normal  ScalingReplicaSet  117s  deployment-controller  Scaled down replica set rollout-nginx-cb7dd7f4b to 0

특정 시점으로 파드 복구

[root@m-k8s ~]# kubectl rollout undo deployment rollout-nginx --to-revision=1
deployment.apps/rollout-nginx rolled back

 

생성된 파드들의 IP 확인

[root@m-k8s ~]# kubectl get pods -o=custom-columns=NAME:.metadata.name,IP:.status.podIP,STATUS:.status.phase,NODE:.spec.nodeName
NAME                             IP               STATUS    NODE
rollout-nginx-64dd56c7b5-nkkg6   172.16.103.145   Running   w2-k8s
rollout-nginx-64dd56c7b5-tmxbh   172.16.132.13    Running   w3-k8s
rollout-nginx-64dd56c7b5-zvv9t   172.16.221.146   Running   w1-k8s

 

nginx 컨테이너 버전 확인

[root@m-k8s ~]# curl -I --silent 172.16.132.13 | grep Server
Server: nginx/1.15.12

 

작업 내역 삭제

[root@m-k8s ~]# kubectl delete -f ~/_Book_k8sInfra/ch3/3.2.10/rollout-nginx.yaml
deployment.apps "rollout-nginx" deleted

[root@m-k8s ~]# kubectl get pods
No resources found in default namespace.

정리

컨테이너의 버전 업그레이드 시행 시 파드 삭제 후 생성

깃허브와 같이 버전관리가 가능하다. ( 단, record옵션을 잘 사용해야 할 것)

다음 시간엔 쿠버네티스 외부에서 파드를 이용하는 방법을 포스팅할 예정

반응형