반응형

* 쿠버네티스 공식 문서에서 튜토리얼 진행하며 한국어로 번역하여 정리한 내용입니다.

* https://kubernetes.io/ko/docs/tutorials/ 에서 Katacoda를 사용하여 브라우저 상 터미널로 동일한 내용을 실습해 볼 수 있습니다.

목표 : kubectl set image로 배포된 애플리케이션을 업데이트하고, rollout undo 명령으로 롤백하기

- Step 1 : Update the version of the app

get deployments 명령어로 deployment 목록을 나열해보세요.

$ kubectl get deployments
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   4/4     4            4           17m

get pods 명령어로 실행 중인 포드를 나열해보세요.

$ kubectl get pods
NAME                                  READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-fb5c67579-6gbvm   1/1     Running   0          17m
kubernetes-bootcamp-fb5c67579-7vfcw   1/1     Running   0          17m
kubernetes-bootcamp-fb5c67579-fj5x4   1/1     Running   0          17m
kubernetes-bootcamp-fb5c67579-hllgp   1/1     Running   0          17m

 

앱의 현재 이미지 버전을 보개 위해, describe pods 명령어를 실행해서 Image 필드를 찾아보세요.

$ kubectl describe pods
Name:         kubernetes-bootcamp-fb5c67579-6gbvm
...
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://5fdd4ed1bdee048f8d18f7e548d6092eede00bd849d81da0ddf7035137187614
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1
...
Name:         kubernetes-bootcamp-fb5c67579-7vfcw
...
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://1ddcf9a2cf66112ae4ac762ce732c0a2ebada47626c185ac4a32456ee33f57d3
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1

 

애플리케이션의 이미지를 버전 2로 업데이트하기 위해서,

deployment 이름, 새로운 이미지 버전을 지정하여 set image 명령어를 사용해보세요.

$ kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
deployment.apps/kubernetes-bootcamp image updated

이 명령어는 앱에 다른 이미지를 사용하도록 deployment에 알리고, 롤링 업데이트를 시작했습니다.

새로운 포드의 상태를 확인하고, get pods 명령어로 종료되는 이전의 것을 확인해보세요.

$ kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-7d44784b7c-6cmn6   1/1     Running   0          2m10s
kubernetes-bootcamp-7d44784b7c-72shs   1/1     Running   0          2m7s
kubernetes-bootcamp-7d44784b7c-7fjbw   1/1     Running   0          2m7s
kubernetes-bootcamp-7d44784b7c-fbqt9   1/1     Running   0          2m10s

 

- Step 2 : Verify an update

먼저, 앱이 실행 중인지 확인하세요.

노출된 IP와 포트를 확인하기 위해 describe service 명령을 실행하세요.

$ kubectl describe services/kubernetes-bootcamp
Name:                     kubernetes-bootcamp
Namespace:                default
Labels:                   app=kubernetes-bootcamp
Annotations:              <none>
Selector:                 app=kubernetes-bootcamp
Type:                     NodePort
IP Families:              <none>
IP:                       10.99.20.64
IPs:                      10.99.20.64
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30730/TCP
Endpoints:                172.18.0.10:8080,172.18.0.11:8080,172.18.0.12:8080 + 1 more...
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

노드 포트 값을 NODE_PORT 환경 변수로 만들어주세요.

$ export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
$ echo NODE_PORT=$NODE_PORT
NODE_PORT=30730

다음으로 노출된 IP와 포트에 curl을 사용하세요.

$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7d44784b7c-6cmn6 | v=2
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7d44784b7c-72shs | v=2
$ curl $(minikube ip):$NODE_PORT
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7d44784b7c-fbqt9 | v=2

매번 curl 명령을 실행할 때마다, 다른 포드가 나타날 것입니다.

모든 파드는 최신 버전(v2)로 실행 중입니다.

또, rollout status 명령을 실행해서 업데이트를 확인할 수 있습니다.

$ kubectl rollout status deployments/kubernetes-bootcamp
deployment "kubernetes-bootcamp" successfully rolled out

앱의 현재 이미지 버전을 보기 위해, describe pods 명령을 실행해보세요.

$ kubectl describe pods
Name:         kubernetes-bootcamp-7d44784b7c-6cmn6
...
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://290fccc9a9b87055f7ce17102bb7a8df93bfaee85a83cd3e6456e4620ac0eafb
    Image:          jocatalin/kubernetes-bootcamp:v2
...

Image 필드의 출력으로, 실행 중인 최신 이미지 버전(v2)를 확인할 수 있습니다.

- Step 3 : Rollback an update

또 다른 업데이트를 수행하고, v10으로 태그된 이미지를 배포해봅시다.

$ kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=gcr.io/google-samples/kubernetes-bootcamp:v10
deployment.apps/kubernetes-bootcamp image updated

deployment의 상태를 보기 위해 get deployments를 사용해봅니다.

$ kubectl get deployments
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   3/4     2            3           34m

출력은 원하는 수의 사용 가능한 포드가 나열되지 않습니다.

모든 포드를 나열하도록 get pods 명령어를 실행해봅시다.

$ kubectl get pods
NAME                                   READY   STATUS             RESTARTS   AGE
kubernetes-bootcamp-59b7598c77-chlrp   0/1     ImagePullBackOff   0          2m18s
kubernetes-bootcamp-59b7598c77-x4lzm   0/1     ImagePullBackOff   0          2m18s
kubernetes-bootcamp-7d44784b7c-6cmn6   1/1     Running            0          14m
kubernetes-bootcamp-7d44784b7c-72shs   1/1     Running            0          14m
kubernetes-bootcamp-7d44784b7c-fbqt9   1/1     Running            0          14m

ImagePullBackOff 상태를 가지는 일부 포드가 나타납니다.

문제에 대한 더 많은 인사이트를 얻기 위해, describe pods 명령을 실행합니다.

$ kubectl describe pods
...
Name:         kubernetes-bootcamp-59b7598c77-x4lzm
Namespace:    default
Priority:     0
Node:         minikube/172.17.0.9
Start Time:   Sat, 16 Oct 2021 05:10:36 +0000
Labels:       app=kubernetes-bootcamp
              pod-template-hash=59b7598c77
Annotations:  <none>
Status:       Pending
IP:           172.18.0.5
IPs:
  IP:           172.18.0.5
Controlled By:  ReplicaSet/kubernetes-bootcamp-59b7598c77
Containers:
  kubernetes-bootcamp:
    Container ID:   
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v10
    Image ID:       
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       ImagePullBackOff
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-9zq45 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-9zq45:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-9zq45
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                   From               Message
  ----     ------     ----                  ----               -------
  Normal   Scheduled  3m29s                 default-scheduler  Successfully assigned default/kubernetes-bootcamp-59b7598c77-x4lzm to minikube
  Normal   Pulling    2m (x4 over 3m28s)    kubelet            Pulling image "gcr.io/google-samples/kubernetes-bootcamp:v10"
  Warning  Failed     119s (x4 over 3m26s)  kubelet            Failed to pull image "gcr.io/google-samples/kubernetes-bootcamp:v10": rpc error: code = Unknown desc = Error response from daemon: manifest for gcr.io/google-samples/kubernetes-bootcamp:v10 not found: manifest unknown: Failed to fetch "v10" from request "/v2/google-samples/kubernetes-bootcamp/manifests/v10".
  Warning  Failed     119s (x4 over 3m26s)  kubelet            Error: ErrImagePull
  Warning  Failed     90s (x6 over 3m26s)   kubelet            Error: ImagePullBackOff
  Normal   BackOff    79s (x7 over 3m26s)   kubelet            Back-off pulling image "gcr.io/google-samples/kubernetes-bootcamp:v10"
...

영향이 있는 포드에 대한 출력의 Events 섹션에서, v10 이미지 버전은 레포지토리에 존재하지않는 다는 것을 알려줍니다.

마지막 작업 버전으로 deployment를 롤백시키기 위해, rollout undo 명령어를 사용합시다.

$ kubectl rollout undo deployments/kubernetes-bootcamp
deployment.apps/kubernetes-bootcamp rolled back

rollout undo 명령은 deployment를 이전에 알려진 상태(이미지의 v2)로 되돌립니다.

업데이트는 버전이 지정되고, deployment의 이전에 알려진 상태로 되돌릴 수 있습니다.

다시 get pods 명령으로 포드를 나열해봅시다.

$ kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-7d44784b7c-492sr   1/1     Running   0          111s
kubernetes-bootcamp-7d44784b7c-6cmn6   1/1     Running   0          20m
kubernetes-bootcamp-7d44784b7c-72shs   1/1     Running   0          20m
kubernetes-bootcamp-7d44784b7c-fbqt9   1/1     Running   0          20m

4개의 포드가 실행 중입니다. 이러한 포드에 배포된 이미지를 확인하려면, describe pods 명령을 사용하세요.

$ kubectl describe pods
Name:         kubernetes-bootcamp-7d44784b7c-492sr
...
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://6310e73167bf98b105b3fa51da6afbd2a5ae1523763909376c392e1f2891a953
    Image:          jocatalin/kubernetes-bootcamp:v2
...

deployment는 앱의 안정된 버전(v2)을 다시 사용합니다. 롤백에 성공했습니다.

출처 : https://kubernetes.io/ko/docs/tutorials/kubernetes-basics/update/update-interactive/ 

 

반응형

+ Recent posts