nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 3
selector:
matchLabels:
color: blue
template: # pod의 내용
metadata:
labels:
color: blue
spec:
containers:
- name: test
image: nginx
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl apply -f nginx1.yaml
deployment.apps/test created
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
test 3/3 3 3 12s
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
test-69454c947b-c89d4 1/1 Running 0 109s 10.96.2.16 gke-mytestcluster-default-pool-b3369d01-gtnl <none> <none>
test-69454c947b-np6kq 1/1 Running 0 109s 10.96.1.16 gke-mytestcluster-default-pool-b3369d01-qkz5 <none> <none>
test-69454c947b-sjzkv 1/1 Running 0 109s 10.96.0.15 gke-mytestcluster-default-pool-b3369d01-n9rz <none> <none>
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl rollout history deploy test
deployment.apps/test
REVISION CHANGE-CAUSE
1 <none>
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl delete -f nginx1.yaml
deployment.apps "test" deleted
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl apply -f nginx1.yaml --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/test created
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl rollout history deploy test
deployment.apps/test
REVISION CHANGE-CAUSE
1 kubectl apply --filename=nginx1.yaml --record=true
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 3
selector:
matchLabels:
color: blue
template: # pod의 내용
metadata:
labels:
color: blue
spec:
containers:
- name: test
image: httpd
v1으로 apply 후 kubectl get pod, v2로 apply 후 kubectl get pod를 해볼 것임
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl apply -f nginx1.yaml ; kubectl get pod ; kubectl apply -f nginx2.yaml ; kubectl get pod
deployment.apps/test configured
NAME READY STATUS RESTARTS AGE
test-69454c947b-j28kv 1/1 Running 0 3m57s
test-69454c947b-l2zbc 1/1 Running 0 3m57s
test-69454c947b-zvllt 1/1 Running 0 3m57s
deployment.apps/test configured
NAME READY STATUS RESTARTS AGE
test-69454c947b-j28kv 1/1 Running 0 3m58s
test-69454c947b-l2zbc 1/1 Running 0 3m58s
test-69454c947b-zvllt 1/1 Running 0 3m58s
test-6bcd9c8c7b-xsj7m 0/1 Pending 0 1s
v2로 apply 후 기존 pod 3개가 있는 상태에서 업데이트 → 새로 하나 생성(기존하나 삭제) -롤링업데이트
이런 업데이트는 두가지 방법을 사용할 수 있다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
strategy:
type: Recreate
replicas: 3
selector:
matchLabels:
color: blue
template: # pod의 내용
metadata:
labels:
color: blue
spec:
containers:
- name: test
image: nginx
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl apply -f nginx1.yaml
deployment.apps/test created
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
strategy:
type: Recreate
replicas: 3
selector:
matchLabels:
color: blue
template: # pod의 내용
metadata:
labels:
color: blue
spec:
containers:
- name: test
image: httpd
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl get pod ; kubectl apply -f nginx1.yaml ; kubectl get pod
NAME READY STATUS RESTARTS AGE
test-69454c947b-6jfz6 1/1 Running 0 77s
test-69454c947b-d5vtj 1/1 Running 0 77s
test-69454c947b-pbfsg 1/1 Running 0 77s
deployment.apps/test configured
NAME READY STATUS RESTARTS AGE
test-69454c947b-6jfz6 1/1 Terminating 0 78s
test-69454c947b-d5vtj 1/1 Terminating 0 78s
test-69454c947b-pbfsg 1/1 Terminating 0 78s
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl get pod
NAME READY STATUS RESTARTS AGE
test-6bcd9c8c7b-d9sp2 1/1 Running 0 36s
test-6bcd9c8c7b-dxch8 1/1 Running 0 36s
test-6bcd9c8c7b-qvdwb 1/1 Running 0 36s
3개를 모두 Terminate(종료) 된 후에 한꺼번에 업데이트를 한다.
1) yaml 작성nginx1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 2
replicas: 3
selector:
matchLabels:
color: blue
template: # pod의 내용
metadata:
labels:
color: blue
spec:
containers:
- name: test
image: httpd
kubectl apply -f nginx1.yaml
kubectl get pod ; sed -i 's/image: httpd/image: nginx/' nginx1.yaml ; kubectl apply -f nginx1.yaml ; kubectl get pod
NAME READY STATUS RESTARTS AGE
test-6bcd9c8c7b-gzr7m 1/1 Running 0 25s
test-6bcd9c8c7b-hsp9n 1/1 Running 0 25s
test-6bcd9c8c7b-wbh9d 1/1 Running 0 25s
deployment.apps/test configured
NAME READY STATUS RESTARTS AGE
test-69454c947b-g7ptz 0/1 ContainerCreating 0 0s
test-69454c947b-zx77f 0/1 Pending 0 0s
test-6bcd9c8c7b-gzr7m 1/1 Running 0 25s
test-6bcd9c8c7b-hsp9n 1/1 Terminating 0 25s
test-6bcd9c8c7b-wbh9d 1/1 Terminating 0 25s
2개가 종료되고(하나는 유지), 2개는 새로 생성된다.
dustndus8@cloudshell:~/0902 (rapa-0901-ysy)$ kubectl get pod
NAME READY STATUS RESTARTS AGE
test-69454c947b-g7ptz 1/1 Running 0 39s
test-69454c947b-nrmpd 1/1 Running 0 39s
test-69454c947b-zx77f 1/1 Running 0 39s