nginx를 deployment를 통해 배포

root@ip-172-31-4-27:~# kubectl create deployment nginx --image=nginx
	deployment.apps/nginx created
	root@ip-172-31-4-27:~# kubectl get deploy
	NAME      READY   UP-TO-DATE   AVAILABLE   AGE
	example   1/1     1            1           18m
	nginx     1/1     1            1           12s

deploy, service, endpoint, pod 확인

root@ip-172-31-4-27:~# kubectl scale deployment nginx --replicas=3
root@ip-172-31-4-27:~# kubectl get deploy,svc,ep,po
	NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
	deployment.apps/nginx   3/3     3            3           2m8s

	NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
	service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   25h

	NAME                   ENDPOINTS          AGE
	endpoints/kubernetes   172.31.4.27:6443   25h

	NAME                         READY   STATUS    RESTARTS   AGE
	pod/nginx-6799fc88d8-77kj6   1/1     Running   0          13s
	pod/nginx-6799fc88d8-8t5cp   1/1     Running   0          13s
	pod/nginx-6799fc88d8-v9m2z   1/1     Running   0          23h

nginx image 확인

root@ip-172-31-4-27:~# kubectl describe deployments nginx |grep -i image
    Image:        nginx

record하면 rollout history할때 기록이 남는다. (구체적으로 확인가능)

root@ip-172-31-4-27:~# kubectl set image deploy nginx nginx=nginx:1.14.2 --record
	deployment.apps/nginx image updated

history 확인

root@ip-172-31-4-27:~# kubectl rollout history deployment nginx
	deployment.apps/nginx 
	REVISION  CHANGE-CAUSE
	1         <none>
	2         kubectl set image deploy nginx nginx=nginx:1.14.2 --record=true

revision=2에 nginx:1.14.2 확인

root@ip-172-31-4-27:~# kubectl rollout history deployment nginx --revision=2
	deployment.apps/nginx with revision #2
	Pod Template:
	  Labels:	app=nginx
		pod-template-hash=75d64795db
	  Annotations:	kubernetes.io/change-cause: kubectl set image deploy nginx nginx=nginx:1.14.2 --record=true
	  Containers:
	   nginx:
		Image:	nginx:1.14.2
		Port:	<none>
		Host Port:	<none>
		Environment:	<none>
		Mounts:	<none>
	  Volumes:	<none>

revision=1에 nginx:latest 확인

root@ip-172-31-4-27:~# kubectl rollout history deployment nginx --revision=1
	deployment.apps/nginx with revision #1
	Pod Template:
	  Labels:	app=nginx
		pod-template-hash=6799fc88d8
	  Containers:
	   nginx:
		Image:	nginx
		Port:	<none>
		Host Port:	<none>
		Environment:	<none>
		Mounts:	<none>
	  Volumes:	<none>

 

root@ip-172-31-4-27:~# kubectl get deploy,rs,po
	NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
	deployment.apps/nginx   3/3     3            3           8m33s

	NAME                               DESIRED   CURRENT   READY   AGE
	replicaset.apps/nginx-6799fc88d8   0         0         0       23h
	replicaset.apps/nginx-75d64795db   3         3         3       3m48s

	NAME                         READY   STATUS    RESTARTS   AGE
	pod/nginx-75d64795db-4qjp8   1/1     Running   0          3m30s
	pod/nginx-75d64795db-52l87   1/1     Running   0          3m48s
	pod/nginx-75d64795db-frbc8   1/1     Running   0          3m39s

 

root@ip-172-31-4-27:~# kubectl describe po nginx-75d64795db-4qjp8 |grep -i image
		Image:          nginx:1.14.2
		Image ID:       docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
	  Normal  Pulling    7m34s  kubelet            Pulling image "nginx:1.14.2"
	  Normal  Pulled     7m30s  kubelet            Successfully pulled image "nginx:1.14.2" in 3.371438963s

rollout 수행

root@ip-172-31-4-27:~# kubectl rollout undo deployment nginx --to-revision=1
	deployment.apps/nginx rolled back

rollout 상태 확인

root@ip-172-31-4-27:~# kubectl rollout status deployment nginx
	Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
	Waiting for deployment "nginx" rollout to finish: 1 old replicas are pending termination...
	deployment "nginx" successfully rolled out

최초 nginx latest 버전으로 돌아온 것을 확인

root@ip-172-31-4-27:~# kubectl describe po nginx-6799fc88d8-98x77 |grep -i image
		Image:          nginx
		Image ID:       docker-pullable://nginx@sha256:6b1daa9462046581ac15be20277a7c75476283f969cb3a61c8725ec38d3b01c3
	  Normal  Pulling    43s   kubelet            Pulling image "nginx"
	  Normal  Pulled     40s   kubelet            Successfully pulled image "nginx" in 3.241107792s

+ Recent posts