②. 使用命令的方式实现滚动更新
kubectl set image deployment/my-dep nginx=nginx:1.16.1 --record(注意这里的nginx=nginx:1.16.1第一个nginx需要通过命令 kubectl get deploy my-dep-01 -oyaml查看到)
# 实时的去监控 [root@k8smaster ~]# kubectl get pod -w NAME READY STATUS RESTARTS AGE my-dep-01-686cfb7bf-8hwp8 1/1 Running 1 11h my-dep-01-686cfb7bf-9g2ws 1/1 Running 1 11h my-dep-01-686cfb7bf-9jz5m 1/1 Running 1 11h my-dep-01-686cfb7bf-b54z6 1/1 Running 1 11h my-dep-01-686cfb7bf-xhvjz 1/1 Running 1 11h # 使用如下命令后,会出现下图的效果 [root@k8smaster ~]# kubectl get deploy my-dep-01 -0yaml
③. 更新好之后,使用如下命令监控可以看到已经进行了替换
# 通过命令我们已经发生了滚动更新,将nginx:laster的版本更新到了nginx:1.16.1 [root@k8smaster ~]# kubectl get deploy my-dep-01 -oyaml |grep nginx kubernetes.io/change-cause: kubectl set image deployment/my-dep-01 my-dep-01=nginx:1.16.1 - image: nginx:1.16.1
⑧. Deployment:版本回退
- ①. 通过kubectl rollout history deployment/my-dep-01查看之前的历史,2这个版本我们将nginx改为了1.16.1的版本,然后我们使用命令进行回退,又将1.16.1的版本改为了latest
[root@k8smaster ~]# kubectl rollout history deployment/my-dep-01 deployment.apps/my-dep-01 REVISION CHANGE-CAUSE 1 <none> 2 kubectl set image deployment/my-dep-01 my-dep-01=nginx:1.16.1 --record=true [root@k8smaster ~]# kubectl rollout undo deployment/my-dep-01 --to-revision=1 deployment.apps/my-dep-01 rolled back [root@k8smaster ~]# kubectl get deploy my-dep-01 -oyaml |grep nginx - image: nginx
②. 版本回退常用命令