ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [따배쿠] Controller - Deployment
    kubernetes 2024. 12. 5. 09:27

    Deployment

    • ReplicaSet을 제어해주는 부모 역할
    • ReplicaSet을 컨트롤해서 Pod 수 조절
      • Deployment -> ReplicaSet -> Pod 순으로 컨트롤
      • Deployment가 ReplicaSet을 Control하고, ReplicaSet이 Pod를 컨트롤
    • 목적 : Pod 수 조절 & Rolling update & Rolling back
      • Rolling update? 
        • 애플리케이션의 새로운 버전을 점진적으로 배포하는 방법으로, 서비스의 가용성을 유지하면서 업데이트를 수행할 수 있도록 돕습니다.
        • kubectl set image deployment <deploy_name> <container_name> = <new_version_image>
        • kubectl rollout history deployment <deploy_name> # 업데이트 히스토리 확인
      • Rolling Back?
        • 애플리케이션의 이전 버전으로 되돌리는 과정입니다. 이는 주로 새로운 버전의 배포 중에 문제가 발생했을 때 사용되며, 서비스의 가용성을 유지하면서 신속하게 안정적인 상태로 복구할 수 있도록 돕습니다.
        • kubectl rollout undo deploy <deploy_name>
      • Rolling update control
        • kubectl rollout status deployment app-deploy # 업데이트 상태 확인
        • kubectl rollout pause deployment app-deploy # 업데이트 중지
        • kubectl rollout resume deployment app-deploy # 업데이트 재개

     

    Deployment Definition

     

     

    ReplicaSet과 Deployment definition의 차이점이 크게 없다. (kind만 달라짐)

    즉, Deployment를 가지고도 Replicaset 운영하듯이 가능하다.

     

    예시

     

    # deploy-nginx.yaml 파일 작성

    root@master:~/Getting-Start-Kubernetes/6# vi deploy-nginx.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: deploy-nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: webui
      template:
        metadata:
          name: nginx-pod
          labels:
            app: webui
        spec:
          containers:
          - name: nginx-container
            image: nginx:1.14

     

    # 생성 및 확인

    root@master:~/Getting-Start-Kubernetes/6# kubectl create -f deploy-nginx.yaml
    deployment.apps/deploy-nginx created
    root@master:~/Getting-Start-Kubernetes/6# kubectl get deploy,rs,pod
    NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/deploy-nginx   3/3     3            3           4m24s
    
    NAME                                     DESIRED   CURRENT   READY   AGE
    replicaset.apps/deploy-nginx-5f67dcf6d   3         3         3       4m24s
    
    NAME                               READY   STATUS    RESTARTS   AGE
    pod/deploy-nginx-5f67dcf6d-b55l7   1/1     Running   0          4m24s
    pod/deploy-nginx-5f67dcf6d-fm58s   1/1     Running   0          4m24s
    pod/deploy-nginx-5f67dcf6d-s9wq9   1/1     Running   0          4m24s

     

    이름만 보고도 유추 가능

    pod의 부모가 replicaset, replicaset의 부모가 deployment

     

    Deployment Rolling Update & Rolling back 기능

     

    Flow

     

    1. Deployment 배포 (replicas=3, nginx:1.14)

    2. Deployment에 의해 Replicaset(xxx)가 만들어지고, Replicaset에 의해 pod 3개(nginx:1.14)가 만들어진다.

    3. kubectl set image deployment app-deploy app=nginx:1.15 --record 명령어로 Rolling Update 요청

    4. 새로운 Replicaset(yyy)이 만들어지고, 해당 Replicaset은 pod를 1개(nginx:1.15) 생성한다.

    5. pod(nginx:1.15) 1개가 생성되면, Deployment는 Replicaset(xxx)의 갯수를 2개로 줄이면서, pod(nginx:1.14) 1개를 삭제한다.

    (현재 pod는 1.14, 1.14, 1.15 이렇게 배포되어있는 상황)

    6. 이제 Replicaset(yyy)의 갯수가 2개로 늘어난다. 이에 따라 pod가 (nginx:1.15) 1개 더 생성 되었다. 

    7. 다시 Replicaset(xxx)의 갯수가 1개로 줄어든다.

    (현재 pod는 1.14, 1.15, 1.15 이렇게 배포되어있는 상황)

    8. Replicaset(yyy)의 갯수가 3개로 늘어났고, pod가 (nginx:1.15) 1개 더 생성 되었다.

    9. 다시 Replicaset(xxx)의 갯수가 0개로 줄어든다.

    (현재 pod는 1.15, 1.15, 1.15 이렇게 배포되어있는 상황)

    10. 이에 따라 서비스 운영 중에도 중단 없이 update가 가능하다.

     

    예시 (Rolling update)

     

    # deployment-exam1.yaml 파일 작성

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: app-deploy
    spec:
      selector:
        matchLabels:
          app: webui
      replicas: 3
      template:
        metadata:
          labels:
            app: webui
        spec:
          containers:
          - image: nginx:1.14
            name: web
            ports:
            - containerPort: 80

     

    # 생성 및 확인

    root@master:~/Getting-Start-Kubernetes/6# kubectl create -f deployment-exam1.yaml --record
    deployment.apps/app-deploy created

     


    --record 옵션은 업데이트 과정을 history로 기록합니당

    NAME                          READY   STATUS              RESTARTS   AGE     IP                NODE    NOMINATED NODE   READINESS GATES
    app-deploy-5486c74cb4-8q2cs   0/1     ContainerCreating   0          1s      <none>            node1   <none>           <none>
    app-deploy-5486c74cb4-qx625   1/1     Running             0          12s     192.168.104.45    node2   <none>           <none>
    app-deploy-5486c74cb4-r4khm   1/1     Running             0          3s      192.168.166.184   node1   <none>           <none>
    app-deploy-76b844f55f-7g2tx   1/1     Running             0          6m44s   192.168.166.182   node1   <none>           <none>
    app-deploy-76b844f55f-m2g8m   0/1     Terminating         0          6m44s   192.168.104.44    node2   <none>           <none>

     

    새로운 pod가 생성됨과 동시에, 기존 pod는 종료됩니당

     

    
    root@master:~/Getting-Start-Kubernetes/6# kubectl describe pod app-deploy-5486c74cb4-8q2cs
    Name:             app-deploy-5486c74cb4-8q2cs
    Namespace:        default
    Priority:         0
    Service Account:  default
    Node:             node1/10.100.0.101
    Start Time:       Thu, 05 Dec 2024 02:08:53 +0000
    Labels:           app=webui
                      pod-template-hash=5486c74cb4
    Annotations:      cni.projectcalico.org/containerID: 3bf28eca57348bbb3496a5cd8cc03ea90f9611e252db0b413fe6f5d0eeda7d7d
                      cni.projectcalico.org/podIP: 192.168.166.185/32
                      cni.projectcalico.org/podIPs: 192.168.166.185/32
    Status:           Running
    IP:               192.168.166.185
    IPs:
      IP:           192.168.166.185
    Controlled By:  ReplicaSet/app-deploy-5486c74cb4
    Containers:
      web:
        Container ID:   containerd://5b2780cd9f4410c564ebff4e11903d0149ffc524620b473be7aa6516a61e3b97
        Image:          nginx:1.15
        Image ID:       docker.io/library/nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
        Port:           80/TCP
        Host Port:      0/TCP
        State:          Running
          Started:      Thu, 05 Dec 2024 02:08:54 +0000
        Ready:          True
        Restart Count:  0
        Environment:    <none>
        Mounts:
          /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-6gt5w (ro)
    Conditions:
      Type                        Status
      PodReadyToStartContainers   True
      Initialized                 True
      Ready                       True
      ContainersReady             True
      PodScheduled                True
    Volumes:
      kube-api-access-6gt5w:
        Type:                    Projected (a volume that contains injected data from multiple sources)
        TokenExpirationSeconds:  3607
        ConfigMapName:           kube-root-ca.crt
        ConfigMapOptional:       <nil>
        DownwardAPI:             true
    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  41s   default-scheduler  Successfully assigned default/app-deploy-5486c74cb4-8q2cs to node1
      Normal  Pulled     40s   kubelet            Container image "nginx:1.15" already present on machine
      Normal  Created    40s   kubelet            Created container web
      Normal  Started    40s   kubelet            Started container web

     

     

    describe 명령어로 확인 시, nginx:1.15 버전으로 잘 Rolling update가 된 것을 확인 가능합니당

     

    # Rolling update 실행

    kubectl set image deployment app-deploy web=nginx:1.16 --record

     

    1.16 버전으로 업데이트를 해봅시당

     

    # Rolling update control

    kubectl rollout status deployment app-deploy # 상태 확인
    kubectl rollout pause deployment app-deploy # 업데이트 중지
    kubectl rollout resume deployment app-deploy # 업데이트 재개

     

    참고로, Rolling update 진행 시 상태 확인 / 중단 / 재개도 해당 명령어로 가능합니당

     

    # Rolling update history 확인

    root@master:~/Getting-Start-Kubernetes/6# kubectl rollout history deployment app-deploy
    deployment.apps/app-deploy
    REVISION  CHANGE-CAUSE
    1         kubectl create --filename=deployment-exam1.yaml --record=true
    2         kubectl set image deployment app-deploy web=nginx:1.15 --record=true
    3         kubectl set image deployment app-deploy web=nginx:1.16 --record=true
    4         kubectl set image deployment app-deploy web=nginx:1.17 --record=true

     

    해당 명령어 조회 시, Rolling update history 확인 가능

     

    예시2 (Rolling back)

     

    # Rolling update history 확인

    root@master:~# kubectl rollout history deployment app-deploy
    deployment.apps/app-deploy
    REVISION  CHANGE-CAUSE
    1         kubectl create --filename=deployment-exam1.yaml --record=true
    2         kubectl set image deployment app-deploy web=nginx:1.15 --record=true
    3         kubectl set image deployment app-deploy web=nginx:1.16 --record=true
    4         kubectl set image deployment app-deploy web=nginx:1.17 --record=true

     

    여기서 nginx:1.16 버전으로 rollback 해보자

     

    # kubectl rollout undo ~ 명령으로 rollback

    root@master:~# kubectl rollout undo deployment app-deploy --to-revision=3
    deployment.apps/app-deploy rolled back

     

    *--to-revision=[REVISION 값] : REVISION 값으로 롤백

     

    즉 여기서는 revision 값을 3으로 지정해주었고, 해당 값인 nginx:1.16 버전으로 rollback 된다.

     

    # 확인

    root@master:~# kubectl get pods
    NAME                          READY   STATUS    RESTARTS   AGE
    app-deploy-6f8cb5d6bf-25w6f   1/1     Running   0          2m45s
    app-deploy-6f8cb5d6bf-6wj7p   1/1     Running   0          2m46s
    app-deploy-6f8cb5d6bf-956k9   1/1     Running   0          2m43s
    root@master:~# kubectl describe pod app-deploy-6f8cb5d6bf-956k9
    Name:             app-deploy-6f8cb5d6bf-956k9
    Namespace:        default
    Priority:         0
    Service Account:  default
    Node:             node2/10.100.0.102
    Start Time:       Thu, 05 Dec 2024 04:16:10 +0000
    Labels:           app=webui
                      pod-template-hash=6f8cb5d6bf
    Annotations:      cni.projectcalico.org/containerID: fd39a35a53a9f76530bf62f2ed6ce9289db875a2776dc915e37699d325e666ae
                      cni.projectcalico.org/podIP: 192.168.104.49/32
                      cni.projectcalico.org/podIPs: 192.168.104.49/32
    Status:           Running
    IP:               192.168.104.49
    IPs:
      IP:           192.168.104.49
    Controlled By:  ReplicaSet/app-deploy-6f8cb5d6bf
    Containers:
      web:
        Container ID:   containerd://475018c40bd25575aa7c9717d5c089ace262d7f91fddad741235a8d3f8a70c7e
        Image:          nginx:1.16
        Image ID:       docker.io/library/nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c
        Port:           80/TCP
        Host Port:      0/TCP
        State:          Running
          Started:      Thu, 05 Dec 2024 04:16:11 +0000
        Ready:          True
        Restart Count:  0
        Environment:    <none>
        Mounts:
          /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-vtlll (ro)
    Conditions:
      Type                        Status
      PodReadyToStartContainers   True
      Initialized                 True
      Ready                       True
      ContainersReady             True
      PodScheduled                True
    Volumes:
      kube-api-access-vtlll:
        Type:                    Projected (a volume that contains injected data from multiple sources)
        TokenExpirationSeconds:  3607
        ConfigMapName:           kube-root-ca.crt
        ConfigMapOptional:       <nil>
        DownwardAPI:             true
    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  2m54s  default-scheduler  Successfully assigned default/app-deploy-6f8cb5d6bf-956k9 to node2
      Normal  Pulled     2m53s  kubelet            Container image "nginx:1.16" already present on machine
      Normal  Created    2m53s  kubelet            Created container web
      Normal  Started    2m53s  kubelet            Started container web

     

    nginx:1.16 버전으로 rollback된 것을 확인 가능하다.

     

    # history 확인

    root@master:~# kubectl rollout history deployment app-deploy
    deployment.apps/app-deploy
    REVISION  CHANGE-CAUSE
    1         kubectl create --filename=deployment-exam1.yaml --record=true
    2         kubectl set image deployment app-deploy web=nginx:1.15 --record=true
    4         kubectl set image deployment app-deploy web=nginx:1.17 --record=true
    5         kubectl set image deployment app-deploy web=nginx:1.16 --record=true

     

    revision 3번 값으로 rollback이 됨과 동시에, history에 사라진 것을 확인 가능하다.

    제일 최신 history인 5번에 위치하고 있다. 

     

    # rollback 및 확인

    root@master:~# kubectl rollout undo deployment app-deploy
    deployment.apps/app-deploy rolled back
    root@master:~# kubectl rollout history deployment app-deploy
    deployment.apps/app-deploy
    REVISION  CHANGE-CAUSE
    1         kubectl create --filename=deployment-exam1.yaml --record=true
    2         kubectl set image deployment app-deploy web=nginx:1.15 --record=true
    5         kubectl set image deployment app-deploy web=nginx:1.16 --record=true
    6         kubectl set image deployment app-deploy web=nginx:1.17 --record=true

     

    다시 rollback을 하면, 직전 rollback 기록인 1.17로 되돌아가고, history에도 남는다.

     

     

     

    Deployment Rolling Update & Rolling back 세부 기능

    • yaml 파일 내 annotations을 통해서, 쿠버네티스에게 특정 정보 전달이 가능하다.
      •   annotations:
            kubernetes.io/change-cause: version 1.15
    • yaml 파일 내 spec을 통해서 Deployment의 Rolling update 세부 기능 조정이 가능하다.
      • progressDeadlineSeconds:
        Deployment가 진행 중인 상태에서 완료되기까지의 최대 시간을 초 단위로 설정합니다.
      • revisionHistoryLimit:
        보관할 이전 리비전의 최대 수를 설정합니다.
      • strategy:
        rollingUpdate:
        maxSurge:
        업데이트 중에 추가로 생성할 수 있는 파드의 최대 비율입니다
        maxUnavailable:
        업데이트 중에 사용할 수 없는 파드의 최대 비율입니다.
        type: RollingUpdate
        업데이트 전략의 유형을 지정합니다. 여기서는 롤링 업데이트 방식입니다.

     

    예시

     

    # deployment-exam2.yaml 파일 작성 (nginx:1.15)

    root@master:~/Getting-Start-Kubernetes/6# vi deployment-exam2.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: deploy-nginx
      annotations:
        kubernetes.io/change-cause: version 1.15
    spec:
      progressDeadlineSeconds: 600
      revisionHistoryLimit: 10
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      replicas: 3
      selector:
        matchLabels:
          app: webui
      template:
        metadata:
          labels:
            app: webui
        spec:
          containers:
          - name: web
            image: nginx:1.15
            ports:
            - containerPort: 80

     

    # 생성 및 확인

    root@master:~/Getting-Start-Kubernetes/6# kubectl apply -f deployment-exam2.yaml
    deployment.apps/deploy-nginx created
    root@master:~/Getting-Start-Kubernetes/6# kubectl get pods
    NAME                            READY   STATUS    RESTARTS   AGE
    deploy-nginx-5486c74cb4-5djfj   1/1     Running   0          37s
    deploy-nginx-5486c74cb4-ptwq6   1/1     Running   0          37s
    deploy-nginx-5486c74cb4-swhxm   1/1     Running   0          37s
    root@master:~/Getting-Start-Kubernetes/6# kubectl describe pod deploy-nginx-5486c74cb4-5djfj
    Name:             deploy-nginx-5486c74cb4-5djfj
    Namespace:        default
    Priority:         0
    Service Account:  default
    Node:             node2/10.100.0.102
    Start Time:       Thu, 05 Dec 2024 04:32:12 +0000
    Labels:           app=webui
                      pod-template-hash=5486c74cb4
    Annotations:      cni.projectcalico.org/containerID: 266241526d50f381599f0ed3d629a70eb91bb5a674c05379566f5c96ac4d6e01
                      cni.projectcalico.org/podIP: 192.168.104.52/32
                      cni.projectcalico.org/podIPs: 192.168.104.52/32
    Status:           Running
    IP:               192.168.104.52
    IPs:
      IP:           192.168.104.52
    Controlled By:  ReplicaSet/deploy-nginx-5486c74cb4
    Containers:
      web:
        Container ID:   containerd://50af925c388d6531b4271be9770293f34d15df757e67a75528a8e8c9423e9d30
        Image:          nginx:1.15
        Image ID:       docker.io/library/nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
        Port:           80/TCP
        Host Port:      0/TCP
        State:          Running
          Started:      Thu, 05 Dec 2024 04:32:13 +0000
        Ready:          True
        Restart Count:  0
        Environment:    <none>
        Mounts:
          /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9nld6 (ro)
    Conditions:
      Type                        Status
      PodReadyToStartContainers   True
      Initialized                 True
      Ready                       True
      ContainersReady             True
      PodScheduled                True
    Volumes:
      kube-api-access-9nld6:
        Type:                    Projected (a volume that contains injected data from multiple sources)
        TokenExpirationSeconds:  3607
        ConfigMapName:           kube-root-ca.crt
        ConfigMapOptional:       <nil>
        DownwardAPI:             true
    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  58s   default-scheduler  Successfully assigned default/deploy-nginx-5486c74cb4-5djfj to node2
      Normal  Pulled     58s   kubelet            Container image "nginx:1.15" already present on machine
      Normal  Created    58s   kubelet            Created container web
      Normal  Started    57s   kubelet            Started container web

     

    nginx:1.15 버전으로 배포된 것을 확인 가능하다.

     

    # deployment-exam2.yaml 파일 작성 (nginx:1.16)

    root@master:~/Getting-Start-Kubernetes/6# vi deployment-exam2.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: deploy-nginx
      annotations:
        kubernetes.io/change-cause: version 1.16
    spec:
      progressDeadlineSeconds: 600
      revisionHistoryLimit: 10
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      replicas: 3
      selector:
        matchLabels:
          app: webui
      template:
        metadata:
          labels:
            app: webui
        spec:
          containers:
          - name: web
            image: nginx:1.16
            ports:
            - containerPort: 80

     

    annotation 부분과 spec 내 image를 1.16 버전으로 수정해준다.

    사실 중요한건 spec 내 image 버전을 수정해줘야 진짜 버전 업데이트가 됨 !!

     

    # 수정 및 확인

    root@master:~/Getting-Start-Kubernetes/6# kubectl apply -f deployment-exam2.yaml
    deployment.apps/deploy-nginx configured
    root@master:~/Getting-Start-Kubernetes/6# kubectl get pods
    NAME                            READY   STATUS    RESTARTS   AGE
    deploy-nginx-6f8cb5d6bf-f8pz4   1/1     Running   0          14s
    deploy-nginx-6f8cb5d6bf-n8gc8   1/1     Running   0          15s
    deploy-nginx-6f8cb5d6bf-q2rg2   1/1     Running   0          12s
    root@master:~/Getting-Start-Kubernetes/6# kubectl describe pods deploy-nginx-6f8cb5d6bf-f8pz4
    Name:             deploy-nginx-6f8cb5d6bf-f8pz4
    Namespace:        default
    Priority:         0
    Service Account:  default
    Node:             node1/10.100.0.101
    Start Time:       Thu, 05 Dec 2024 04:34:21 +0000
    Labels:           app=webui
                      pod-template-hash=6f8cb5d6bf
    Annotations:      cni.projectcalico.org/containerID: 85514dcf9e0d5684391e42c593b68bb64ea16e4991c788aca53e4de1435ef227
                      cni.projectcalico.org/podIP: 192.168.166.130/32
                      cni.projectcalico.org/podIPs: 192.168.166.130/32
    Status:           Running
    IP:               192.168.166.130
    IPs:
      IP:           192.168.166.130
    Controlled By:  ReplicaSet/deploy-nginx-6f8cb5d6bf
    Containers:
      web:
        Container ID:   containerd://fe08432282f3b22cd7eeda93f8c9e198050e1b94b4e848fee9500461ad0712af
        Image:          nginx:1.16
        Image ID:       docker.io/library/nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c
        Port:           80/TCP
        Host Port:      0/TCP
        State:          Running
          Started:      Thu, 05 Dec 2024 04:34:22 +0000
        Ready:          True
        Restart Count:  0
        Environment:    <none>
        Mounts:
          /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-hq6dz (ro)
    Conditions:
      Type                        Status
      PodReadyToStartContainers   True
      Initialized                 True
      Ready                       True
      ContainersReady             True
      PodScheduled                True
    Volumes:
      kube-api-access-hq6dz:
        Type:                    Projected (a volume that contains injected data from multiple sources)
        TokenExpirationSeconds:  3607
        ConfigMapName:           kube-root-ca.crt
        ConfigMapOptional:       <nil>
        DownwardAPI:             true
    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  41s   default-scheduler  Successfully assigned default/deploy-nginx-6f8cb5d6bf-f8pz4 to node1
      Normal  Pulled     40s   kubelet            Container image "nginx:1.16" already present on machine
      Normal  Created    40s   kubelet            Created container web
      Normal  Started    40s   kubelet            Started container web

     

    # rollout history 확인

    root@master:~/Getting-Start-Kubernetes/6# kubectl rollout history deployment deploy-nginx
    deployment.apps/deploy-nginx
    REVISION  CHANGE-CAUSE
    1         version 1.15
    2         version 1.16

     

     

    퀴즈

    • 다음의 조건으로 Deployment를 사용하는 dep-lab.yaml 파일을 생성하고 apply 명령으로 동작시킵니다.
      • labels (name: apache, app: main, rel: stable)을 가지는 httpd:2.2 버전의 Pod를 2개 히스토리로 기록하며 운영합니다.
      • annotations (kubernetes.io/change-cause : version 2.2)를 추가로 설정합니다.
        • deployment name: dep-mainui
        • container: httpd:2.2
    root@master:~/Getting-Start-Kubernetes/6# vi dep-lab.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: dep-mainui
      annotations:
        kubernetes.io/change-cause: version 2.2
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: main
      template:
        metadata:
          labels:
            name: apache
            app: main
            rel: stable
        spec:
          containers:
          - name: web
            image: httpd:2.2
            ports:
            - containerPort: 80

     

    root@master:~/Getting-Start-Kubernetes/6# kubectl apply -f dep-lab.yaml --record
    Flag --record has been deprecated, --record will be removed in the future
    deployment.apps/dep-mainui created
    • 동작 되는 dep-lab.yaml의 이미지를 httpd:2.4 버전으로 rolling update 합니다.
      • 단, apply 명령을 통해 rolling update를 진행합니다.
    root@master:~/Getting-Start-Kubernetes/6# vi dep-lab.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: dep-mainui
      annotations:
        kubernetes.io/change-cause: version 2.4
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: main
      template:
        metadata:
          labels:
            name: apache
            app: main
            rel: stable
        spec:
          containers:
          - name: web
            image: httpd:2.4
            ports:
            - containerPort: 80
    root@master:~/Getting-Start-Kubernetes/6# kubectl apply -f dep-lab.yaml --record
    Flag --record has been deprecated, --record will be removed in the future
    deployment.apps/dep-mainui configured
    • 현재의 dep-mainui 히스토리를 확인하고, rollback 시킵니다.
    root@master:~/Getting-Start-Kubernetes/6# kubectl rollout history deployment dep-mainui
    deployment.apps/dep-mainui
    REVISION  CHANGE-CAUSE
    1         kubectl apply --filename=dep-lab.yaml --record=true
    2         kubectl apply --filename=dep-lab.yaml --record=true
    root@master:~/Getting-Start-Kubernetes/6# kubectl rollout undo deployment dep-mainui
    deployment.apps/dep-mainui rolled back
    • 현재 동작중인 Pod의 httpd 이미지 버전은 어떻게 되는지 확인합니다.
    root@master:~/Getting-Start-Kubernetes/6# kubectl get pods
    NAME                          READY   STATUS    RESTARTS   AGE
    dep-mainui-67b9689c9f-6zjdz   1/1     Running   0          43s
    dep-mainui-67b9689c9f-98b92   1/1     Running   0          44s
    root@master:~/Getting-Start-Kubernetes/6# kubectl describe pods dep-mainui-67b9689c9f-6zjdz
    Name:             dep-mainui-67b9689c9f-6zjdz
    Namespace:        default
    Priority:         0
    Service Account:  default
    Node:             node2/10.100.0.102
    Start Time:       Thu, 05 Dec 2024 05:21:11 +0000
    Labels:           app=main
                      name=apache
                      pod-template-hash=67b9689c9f
                      rel=stable
    Annotations:      cni.projectcalico.org/containerID: f095f48da1c70d2ad5a229fd3323c506e1450dc1f8057b67b6a1f3dfab496a82
                      cni.projectcalico.org/podIP: 192.168.104.57/32
                      cni.projectcalico.org/podIPs: 192.168.104.57/32
    Status:           Running
    IP:               192.168.104.57
    IPs:
      IP:           192.168.104.57
    Controlled By:  ReplicaSet/dep-mainui-67b9689c9f
    Containers:
      web:
        Container ID:   containerd://eeb4a90bd2ee0d4bb75232834e739327bb8a5f4045f1e0a74829c6ae818de3ff
        Image:          httpd:2.2
        Image ID:       docker.io/library/httpd@sha256:9784d70c8ea466fabd52b0bc8cde84980324f9612380d22fbad2151df9a430eb
        Port:           80/TCP
        Host Port:      0/TCP
        State:          Running
          Started:      Thu, 05 Dec 2024 05:21:12 +0000
        Ready:          True
        Restart Count:  0
        Environment:    <none>
        Mounts:
          /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-l7ltt (ro)
    Conditions:
      Type                        Status
      PodReadyToStartContainers   True
      Initialized                 True
      Ready                       True
      ContainersReady             True
      PodScheduled                True
    Volumes:
      kube-api-access-l7ltt:
        Type:                    Projected (a volume that contains injected data from multiple sources)
        TokenExpirationSeconds:  3607
        ConfigMapName:           kube-root-ca.crt
        ConfigMapOptional:       <nil>
        DownwardAPI:             true
    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  62s   default-scheduler  Successfully assigned default/dep-mainui-67b9689c9f-6zjdz to node2
      Normal  Pulled     61s   kubelet            Container image "httpd:2.2" already present on machine
      Normal  Created    61s   kubelet            Created container web
      Normal  Started    61s   kubelet            Started container web

     


    참고 영상

    https://www.youtube.com/watch?v=L5LDBWrP6QU

     

     

Designed by Tistory.