Myluzh Blog

Strive to become a dream architect.

Kubernetes(k8s)-回退版本

发布时间: 2023-6-16 文章作者: myluzh 分类名称: Kubernetes


0x01 发布新版本
1.更新版本
方式一:原先镜像为hellohttp:v1,使用kubectl apply -f app.yaml发布,创建一个新的镜像为hellohttp:v2-error,修改app.yaml中镜像地址为image: registry.cn-hangzhou.aliyuncs.com/myluzh/hellohttp:v2-error,然后重新使用kubectl apply -f app.yaml发布。

方式二:也可以直接通过命令修改镜像,--record 表示把这个命令记录到操作历史中
[root@master ~]# kubectl set image deployment hellohttp hellohttp=registry.cn-hangzhou.aliyuncs.com/myluzh/hellohttp:v2-error --record
Flag --record has been deprecated, --record will be removed in the future
deployment.apps/hellohttp image updated
#查看历史版本
[root@master ~]# kubectl rollout history deployment hellohttp
deployment.apps/hellohttp 
REVISION  CHANGE-CAUSE
3         <none>
4         kubectl set image deployment hellohttp hellohttp=registry.cn-hangzhou.aliyuncs.com/myluzh/hellohttp:v2-error --record=true

2.查看pod状态
查看pod状态,可以看到旧版本pod在关闭
[root@master hellohttp]# kubectl get pod
NAME                         READY   STATUS        RESTARTS   AGE
hellohttp-564dbb8b9d-269xj   1/1     Running       0          18s
hellohttp-564dbb8b9d-cgfnm   1/1     Running       0          12s
hellohttp-78c5857bbd-5v6m6   1/1     Terminating   0          26m
hellohttp-78c5857bbd-b4jg4   1/1     Terminating   0          26m

3.查看更新后的页面
首先设置下pod端口转发
[root@master ~]# kubectl port-forward hellohttp-564dbb8b9d-269xj 8080:8080
使用curl查看最新页面,可以看到已经是新版本的页面 新版本就是输出Error。
[root@master hellohttp]# curl 127.0.0.1:8080
Error!<br>

0x02 查看历史版本
会发现有两个REVISION号
[root@master hellohttp]# kubectl rollout history deployment hellohttp
deployment.apps/hellohttp 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>

0x03 回退版本
#退回到上一个版本
[root@master hellohttp]# kubectl rollout undo deployment hellohttp
deployment.apps/hellohttp rolled back

#退回到指定版本
[root@master hellohttp]# kubectl rollout undo deployment hellohttp --to-revision=1

标签: k8s k8s-depolyment kubernetes

发表评论