
[root@master ~/kube/07/deploy]# kubectl api-resources | grep deploy
deployments deploy apps/v1 true Deployment
[root@master ~/kube/07/deploy]# vi nginx-deploy.yaml
[root@master ~/kube/07/deploy]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
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 ~/kube/07/deploy]# kubectl apply -f nginx-deploy.yaml
deployment.apps/nginx-deploy created
[root@master ~/kube/07/deploy]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deploy-9cc457697-cf4j6 1/1 Running 0 3s
nginx-deploy-9cc457697-qtbgl 1/1 Running 0 3s
nginx-deploy-9cc457697-tsd5d 1/1 Running 0 3s
[root@master ~/kube/07/deploy]# kubectl describe deployments.apps nginx-deploy
Name: nginx-deploy
Namespace: default
CreationTimestamp: Sun, 09 Mar 2025 13:10:51 +0900
Labels: <none>
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=webui
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=webui
Containers:
nginx-container:
Image: nginx:1.14
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deploy-9cc457697 (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 20s deployment-controller Scaled up replica set nginx-deploy-9cc457697 to 3
[root@master ~/kube/07/deploy]# kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deploy-9cc457697 3 3 3 6m17s
[root@master ~/kube/07/deploy]# kubectl describe rs nginx-deploy-9cc457697
Name: nginx-deploy-9cc457697
Namespace: default
Selector: app=webui,pod-template-hash=9cc457697
Labels: app=webui
pod-template-hash=9cc457697
Annotations: deployment.kubernetes.io/desired-replicas: 3
deployment.kubernetes.io/max-replicas: 4
deployment.kubernetes.io/revision: 1
Controlled By: Deployment/nginx-deploy
Replicas: 3 current / 3 desired
Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=webui
pod-template-hash=9cc457697
Containers:
nginx-container:
Image: nginx:1.14
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 6m24s replicaset-controller Created pod: nginx-deploy-9cc457697-tsd5d
Normal SuccessfulCreate 6m24s replicaset-controller Created pod: nginx-deploy-9cc457697-cf4j6
Normal SuccessfulCreate 6m24s replicaset-controller Created pod: nginx-deploy-9cc457697-qtbgl
▶ replicaset은 deployment-controller에 의해 생성되고 pod가 replicaset-controller에 의해 생성됨
▶ deployment ∋ replicasets ∋ pod :: deployment가 replicasets 관리 / replicasets이 pod 관리
[root@master ~/kube/07/roll]# vi deploy-test1.yaml
[root@master ~/kube/07/roll]# cat deploy-test1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
replicas: 3
selector:
matchLabels:
app: webui
template:
metadata:
name: nginx-pod
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.14
rollback test를 위해 --record 적용하여 create or apply
[root@master ~/kube/07/roll]# kubectl apply -f deploy-test1.yaml --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/nginx-deploy configured
[root@master ~/kube/07/roll]# kubectl rollout history deploy nginx-deploy
deployment.apps/nginx-deploy
REVISION CHANGE-CAUSE
1 kubectl apply --filename=deploy-test1.yaml --record=true
현재 이미지 확인
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.14
Image ID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Image: nginx:1.14
Image ID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Image: nginx:1.14
Image ID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
이미지 변경 후 재확인
[root@master ~/kube/07/roll]# kubectl set image deploy nginx-deploy nginx-container=nginx:1.15 --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/nginx-deploy image updated
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
[root@master ~/kube/07/roll]# kubectl set image deploy nginx-deploy nginx-container=nginx:1.16 --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/nginx-deploy image updated
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.16
Image ID:
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.16
Image ID: docker-pullable://nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c
Image: nginx:1.16
Image ID:
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.16
Image ID: docker-pullable://nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c
Image: nginx:1.16
Image ID:
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
▶ rolling update pod 하나 완료하면 기존 pod 하나 삭제하는 방식으로 이뤄짐
▶ 보다 정확히 확인하기 위하여 다음과 같이 모니터링 가능
[root@master ~/kube/07/roll]# kubectl rollout status deployment nginx-deploy
deployment "nginx-deploy" successfully rolled out
[root@master ~/kube/07/roll]# kubectl set image deploy nginx-deploy nginx-container=nginx:1.17 --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/nginx-deploy image updated
[root@master ~/kube/07/roll]# kubectl rollout status deployment nginx-deploy
Waiting for deployment "nginx-deploy" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deploy" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deploy" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deploy" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deploy" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deploy" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "nginx-deploy" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "nginx-deploy" rollout to finish: 1 old replicas are pending termination...
deployment "nginx-deploy" successfully rolled out
rolling update/rollback 전략 확인
[root@master ~/kube/07/roll]# kubectl edit deployments.apps nginx-deploy
---
1 # Please edit the object below. Lines beginning with a '#' will be ignored,
2 # and an empty file will abort the edit. If an error occurs while saving this file will be
3 # reopened with the relevant failures.
4 #
5 apiVersion: apps/v1
6 kind: Deployment
7 metadata:
8 annotations:
9 deployment.kubernetes.io/revision: "4"
10 kubectl.kubernetes.io/last-applied-configuration: |
11 {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{"kubernetes.io/change-cause":"kubectl apply --f ilename=deploy-test1.yaml --record=true"},"name":"nginx-deploy","namespace":"default"},"spec":{"replicas":3,"selector":{"mat chLabels":{"app":"webui"}},"template":{"metadata":{"labels":{"app":"webui"},"name":"nginx-pod"},"spec":{"containers":[{"imag e":"nginx:1.14","name":"nginx-container"}]}}}}
12 kubernetes.io/change-cause: kubectl set image deploy nginx-deploy nginx-container=nginx:1.17
13 --record=true
14 creationTimestamp: "2025-03-09T04:10:51Z"
15 generation: 5
16 name: nginx-deploy
17 namespace: default
18 resourceVersion: "80661"
19 uid: 815f964f-9610-4f9f-8af8-a4220e8c8d4d
20 spec:
21 progressDeadlineSeconds: 600 # 해당 시간 동안 rollingupdate/rollback 안되면 취소
22 replicas: 3
23 revisionHistoryLimit: 10
24 selector:
25 matchLabels:
26 app: webui
27 strategy:
28 rollingUpdate:
29 maxSurge: 25% # spec.replicas 수 기준 최대 새로 추가되는 파드 수
30 maxUnavailable: 25% # spec.replicas 수 기준 최대 이용 불가능 파드 수
31 type: RollingUpdate
---
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.17
Image ID: docker-pullable://nginx@sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
Image: nginx:1.17
Image ID: docker-pullable://nginx@sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
Image: nginx:1.17
Image ID: docker-pullable://nginx@sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
Image: nginx:1.18
Image ID:
▶ 최대 변경 3의 0.25=0.75 반올림 하여 1 개 새로 생성
rollout 기록 확인
[root@master ~/kube/07/roll]# kubectl rollout history deployment nginx-deploy
deployment.apps/nginx-deploy
REVISION CHANGE-CAUSE
1 kubectl apply --filename=deploy-test1.yaml --record=true
2 kubectl set image deploy nginx-deploy nginx-container=nginx:1.15 --record=true
3 kubectl set image deploy nginx-deploy nginx-container=nginx:1.16 --record=true
4 kubectl set image deploy nginx-deploy nginx-container=nginx:1.17 --record=true
5 kubectl set image deploy nginx-deploy nginx-container=nginx:1.18 --record=true
history 통해 바로 이전 버전으로 rollback 진행
[root@master ~/kube/07/roll]# kubectl rollout undo deployment nginx-deploy
deployment.apps/nginx-deploy rolled back
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.17
Image ID: docker-pullable://nginx@sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
Image: nginx:1.17
Image ID: docker-pullable://nginx@sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
Image: nginx:1.17
Image ID: docker-pullable://nginx@sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
[root@master ~/kube/07/roll]# kubectl rollout history deployment nginx-deploy
deployment.apps/nginx-deploy
REVISION CHANGE-CAUSE
1 kubectl apply --filename=deploy-test1.yaml --record=true
2 kubectl set image deploy nginx-deploy nginx-container=nginx:1.15 --record=true
3 kubectl set image deploy nginx-deploy nginx-container=nginx:1.16 --record=true
5 kubectl set image deploy nginx-deploy nginx-container=nginx:1.18 --record=true
6 kubectl set image deploy nginx-deploy nginx-container=nginx:1.17 --record=true
history 통해 특정 상태로 rollback 진행(--to-revision N)
[root@master ~/kube/07/roll]# kubectl rollout undo deployment nginx-deploy --to-revision 2
deployment.apps/nginx-deploy rolled back
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.15
Image ID:
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.17
Image ID: docker-pullable://nginx@sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699
[root@master ~/kube/07/roll]# kubectl rollout history deployment nginx-deploy
deployment.apps/nginx-deploy
REVISION CHANGE-CAUSE
1 kubectl apply --filename=deploy-test1.yaml --record=true
3 kubectl set image deploy nginx-deploy nginx-container=nginx:1.16 --record=true
5 kubectl set image deploy nginx-deploy nginx-container=nginx:1.18 --record=true
6 kubectl set image deploy nginx-deploy nginx-container=nginx:1.17 --record=true
7 kubectl set image deploy nginx-deploy nginx-container=nginx:1.15 --record=true
[root@master ~/kube/07/roll]# kubectl describe pod | grep Image
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
[root@master ~/kube/07/roll]# vi deploy-test2.yaml
[root@master ~/kube/07/roll]# cat deploy-test2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
annotations:
kubernetes.io/change-cause: version 1.14 # '--record' 기능을 수행
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 ~/kube/07/roll]# kubectl apply -f deploy-test2.yaml
deployment.apps/nginx-deploy created
[root@master ~/kube/07/roll]# kubectl rollout history deployment nginx-deploy
deployment.apps/nginx-deploy
REVISION CHANGE-CAUSE
1 version 1.14
kubernetes edit을 통해 annotations 기록 이름 및 이미지 버전 변경
[root@master ~/kube/07/roll]# kubectl edit deployments.apps nginx-deploy
deployment.apps/nginx-deploy edited
---
apiVersion: apps/v1
6 kind: Deployment
7 metadata:
8 annotations:
9 deployment.kubernetes.io/revision: "2"
10 kubectl.kubernetes.io/last-applied-configuration: |
11 {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{"kubernetes.io/change-cause":"version 1.14"},"n ame":"nginx-deploy","namespace":"default"},"spec":{"replicas":3,"selector":{"matchLabels":{"app":"webui"}},"template":{"meta data":{"labels":{"app":"webui"},"name":"nginx-pod"},"spec":{"containers":[{"image":"nginx:1.14","name":"nginx-container"}]}} }}
12 kubernetes.io/change-cause: version 1.15 # version 1.14 ▶ version 1.15
···
37 spec:
38 containers:
39 - image: nginx:1.15 # nginx:1.14 ▶ nginx: 1.15
---
[root@master ~/kube/07/roll]# kubectl rollout history deployment nginx-deploy
deployment.apps/nginx-deploy
REVISION CHANGE-CAUSE
1 version 1.14
2 version 1.15
[root@master ~/kube/07/roll]# kubectl describe pod nginx-deploy | grep Image
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68