业务镜像版本升级及回滚

在指定的deployment中通过kubectl set image指定新版本的 镜像:tag 来实现更新代码的目的。
构建三个不同版本的nginx镜像,第一次使用v1版本,后组逐渐升级到v2与v3,测试镜像版本升级与回滚操作


1:升级到镜像到指定版本:
# kubectl apply -f nginx.yaml --record=true     #v1版本,--record=true为记录执行的kubectl



#镜像更新命令格式为: kubectl set image deployment/deployment-name containers-name=image -n namespace

#V2版本
# kubectl set image deployment/linux36-nginx-deployment linux36-nginx-container=harbor.magedu.net/linux36/nginx-web1:v2 -n linux36
deployment.extensions/linux36-nginx-deployment image updated

#V3版本
# kubectl set image deployment/linux36-nginx-deployment linux36-nginx-container=harbor.magedu.net/linux36/nginx-web1:v3 -n linux36
deployment.extensions/linux36-nginx-deployment image updated


2:查看历史版本信息:
# kubectl rollout history deployment/linux36-nginx-deployment -n linux36  deployment.extensions/linux36-nginx-deployment
REVISION CHANGE-CAUSE
1 kubectl apply --filename=nginx.yaml --record=true
2 kubectl apply --filename=nginx.yaml --record=true
3 kubectl apply --filename=nginx.yaml --record=true




3:回滚到上一个版本:(v3版本回滚V2 ,并生成新的V4)
# kubectl rollout undo deployment/linux36-nginx-deployment -n linux36 deployment.extensions/linux36-nginx-deployment rolled back

查看当前版本号:(v3版本回滚V2 ,并生成新的V4)
# kubectl rollout history deployment/linux36-nginx-deployment -n linux36 deployment.extensions/linux36-nginx-deployment
REVISION CHANGE-CAUSE
1 kubectl apply --filename=nginx.yaml --record=true
3 kubectl apply --filename=nginx.yaml --record=true
4 kubectl apply --filename=nginx.yaml --record=true




4:回滚到指定版本:
# kubectl rollout undo deployment/linux36-nginx-deployment --to-revision=1 -n linux36  deployment.extensions/linux36-nginx-deployment rolled back

回滚后的版本号:(v4版本回滚V1 ,并生成新的V5)
# kubectl rollout history deployment/linux36-nginx-deployment -n linux36  deployment.extensions/linux36-nginx-deployment
REVISION CHANGE-CAUSE
3 kubectl apply --filename=nginx.yaml --record=true
4 kubectl apply --filename=nginx.yaml --record=true
5 kubectl apply --filename=nginx.yaml --record=true

 

posted @ 2023-04-12 12:01  yuanbangchen  阅读(45)  评论(0编辑  收藏  举报