如何将deployment回滚到某个具体的历史版本?

deployment在部署时,会创建RS(replica set)对象,rs对象用于创建具体的pod.

 

所以,回滚deployment到某个历史的版本,就是回滚到具体的RS版本即可。

 

具体怎么来做呢?

 

1、查看目前deployment所有的RS

[root@nccztsjb-node-23 ~]# kubectl get rs
NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-54564779d6   0         0         0       10m
nginx-deployment-5498f778f8   0         0         0       2d18h
nginx-deployment-5898bc4f75   0         0         0       2d19h
nginx-deployment-5b6c6ffbfd   0         0         0       7m39s
nginx-deployment-5dc47dd7fc   0         0         0       2d23h
nginx-deployment-7b6c96955f   0         0         0       2d19h
nginx-deployment-84587f7957   0         0         0       8m42s
nginx-deployment-97576cc54    2         2         2       7m17s
nginx-deployment-98c566774    0         0         0       6m9s
nginx-deployment-c6d7d96cc    0         0         0       2d19h
nginx-deployment-fdb48485c    0         0         0       2d23h

 

2、确定要回滚到哪个RS

比如:这里要回滚到 nginx-deployment-fdb48485c 这个RS

 

3、查看RS的revision即版本信息

[root@nccztsjb-node-23 ~]# kubectl get rs nginx-deployment-fdb48485c -o yaml | grep revision
    deployment.kubernetes.io/revision: "6"

得到的结果是:6

 

4、通过kubectl rollout undo xx --to-revision来指定要回滚到哪个版本

[root@nccztsjb-node-23 ~]# kubectl rollout undo deployment nginx-deployment --to-revision="6"
deployment.apps/nginx-deployment rolled back

 

5、查看是否deployment在使用这个RS

[root@nccztsjb-node-23 ~]# kubectl get rs
NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-54564779d6   0         0         0       17m
nginx-deployment-5498f778f8   0         0         0       2d18h
nginx-deployment-5898bc4f75   0         0         0       2d19h
nginx-deployment-5b6c6ffbfd   0         0         0       15m
nginx-deployment-5dc47dd7fc   0         0         0       2d23h
nginx-deployment-7b6c96955f   0         0         0       2d19h
nginx-deployment-84587f7957   0         0         0       16m
nginx-deployment-97576cc54    0         0         0       14m
nginx-deployment-98c566774    0         0         0       13m
nginx-deployment-c6d7d96cc    0         0         0       2d20h
nginx-deployment-fdb48485c    2         2         2       2d23h # 在用的RS
[root@nccztsjb-node-23 ~]# 

正是指定的RS版本。

 

总结:

  1、核心观点是RS的revision概念,每个RS都有一个revision

  2、通过revision来指定要回滚的具体的版本

 

注意:要确定到回滚到哪个版本,需要通过-o yaml自行查看具体的定义的内容。

 

posted @ 2023-02-06 10:47  Zhai_David  阅读(533)  评论(0编辑  收藏  举报