关于Kubernetes-v1.23.6-资源调度-Deployment-版本的回滚操作
Posted on 2023-09-20 21:43 520_1351 阅读(34) 评论(0) 编辑 收藏 举报先看一下,当前笔者这里的k8s环境,主要是 deployment,rs ,pods 相关的信息
[root@k8s-master ~]# kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 3/3 3 3 24h [root@k8s-master ~]# [root@k8s-master ~]# kubectl get rs NAME DESIRED CURRENT READY AGE nginx-deploy-754898b577 3 3 3 24h nginx-deploy-78d8bf4fd7 0 0 0 24h [root@k8s-master ~]# [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-deploy-754898b577-dpbc2 1/1 Running 1 (24h ago) 24h nginx-deploy-754898b577-mzhvg 1/1 Running 1 (24h ago) 24h nginx-deploy-754898b577-pf7gp 1/1 Running 1 (24h ago) 24h
此时已经有2个rs版本信息了,接入来,我们制造环境,再增加一个rs版本,依然使用最简单的修改镜像的版本,并进行历史版本的查看
[root@k8s-master ~]# kubectl set image deployment/nginx-deploy nginx=nginx:1.9.12 --record=true Flag --record has been deprecated, --record will be removed in the future deployment.apps/nginx-deploy image updated [root@k8s-master ~]# kubectl rollout history deployment/nginx-deploy deployment.apps/nginx-deploy REVISION CHANGE-CAUSE 2 <none> 3 <none> 4 kubectl set image deployment/nginx-deploy nginx=nginx:1.9.12 --record=true
我们再次观察 ,deployment,rs ,pods 相关的信息,发现变化的主要就是rs和pod
[root@k8s-master ~]# kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 3/3 3 3 25h [root@k8s-master ~]# kubectl get rs NAME DESIRED CURRENT READY AGE nginx-deploy-754898b577 0 0 0 25h nginx-deploy-78d8bf4fd7 0 0 0 25h nginx-deploy-8d945596c 3 3 3 3m28s [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-deploy-8d945596c-48bnj 1/1 Running 0 5m25s nginx-deploy-8d945596c-fnthg 1/1 Running 0 6m50s nginx-deploy-8d945596c-lqvqf 1/1 Running 0 8m23s
此时,如果要回滚到上一个版本(REVISION,数字越大,代表的版本越新):
也可以先,查看变更的段,只会显示变改的块相关的内容
[root@k8s-master ~]# kubectl rollout history deployment/nginx-deploy --revision 2 deployment.apps/nginx-deploy with revision #2 Pod Template: Labels: app=nginx-deploy pod-template-hash=754898b577 Containers: nginx: Image: nginx:1.9.1 Port: <none> Host Port: <none> Environment: <none> Mounts: <none> Volumes: <none> [root@k8s-master ~]#
现在开始回滚到上一个版本:即nginx:1.9.1
[root@k8s-master qq-5201351]# kubectl rollout undo deployment/nginx-deploy --to-revision=2 deployment.apps/nginx-deploy rolled back
执行后,我们可以再观察一下 deployment, rs , pods 相关的信息
[root@k8s-master ~]# kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE nginx-deploy 3/3 3 3 25h [root@k8s-master ~]# kubectl get rs NAME DESIRED CURRENT READY AGE nginx-deploy-754898b577 3 3 3 25h nginx-deploy-78d8bf4fd7 0 0 0 25h nginx-deploy-8d945596c 0 0 0 13m [root@k8s-master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deploy-754898b577-d6kmr 1/1 Running 0 22s nginx-deploy-754898b577-qd25d 1/1 Running 0 23s nginx-deploy-754898b577-sk9pc 1/1 Running 0 21s
我们还可以通过 kubectl get deployments -o yaml 看出回退的效果,看看当前的nginx镜像的版本是不是之前的版本
尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17718539.html
作者:一名卑微的IT民工
出处:https://www.cnblogs.com/5201351
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平不高,文章没有高度、深度和广度,只是凑字数,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!