k8s 滚动升级nginx-ingress-controller版本和回退
k8s 滚动升级nginx-ingress-controller版本和回退
·
寻找需要的版本
nginx-ingress地址:https://github.com/kubernetes/ingress-nginx/releases?page=16
-
在浏览器上打开上面的地址
-
复制quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.31.0
(本次演示把quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0升级为quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.31.0)
查看nginx-ingress-controller本地版本
#滚动更新是deployment特有的功能
#查看本地版本
[root@master ~]# kubectl get deploy -n ingress-nginx -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx-ingress-controller 1/1 1 1 118d nginx-ingress-controller quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0 app.kubernetes.io/name=ingress-nginx,app.kubernetes.io/part-of=ingress-nginx
可以看到当前镜像为quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0
滚动更新
#将quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0 升级到quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.31.0
[root@master ~]# kubectl set image deployment nginx-ingress-controller nginx-ingress-controller=quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.31.0 -n ingress-nginx
deployment.apps/nginx-ingress-controller image updated
#查看是否更新
[root@master ~]# kubectl get deploy -n ingress-nginx -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx-ingress-controller 1/1 1 1 118d nginx-ingress-controller quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.31.0 app.kubernetes.io/name=ingress-nginx,app.kubernetes.io/part-of=ingress-nginx
#查看pods是否启动成功
[root@master tomcat]# kubectl get pods -n ingress-nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-ingress-controller-79c6646675-dh5sh 1/1 Running 0 13s 10.244.2.181 node2 <none> <none>
nginx-ingress-controller-7f74f657bd-nhtvn 1/1 Terminating 0 25m 10.244.2.180 node2 <none> <none>
版本回退
如果升级过后pod一直启动不了就需要回退版本
# 查看当前升级版本的状态
[root@k8s-master ~]# kubectl rollout status deploy nginx-ingress-controller -n ingress-nginx
deployment "dep" successfully rolled out
# 查看升级历史记录
[root@k8s-master ~]# kubectl rollout history deploy nginx-ingress-controller -n ingress-nginx
deployment.apps/dep
REVISION CHANGE-CAUSE
1 kubectl create --filename=dep.yaml --record=true
2 kubectl create --filename=dep.yaml --record=true
3 kubectl create --filename=dep.yaml --record=true
# 可以发现有三次版本记录,说明完成过两次升级
# 版本回滚
# 使用--to-revision=1回滚到了1版本
[root@node1 ~]# kubectl rollout undo deployment nginx-ingress-controller --to-revision=1 -n ingress-nginx
deployment.apps/nginx-ingress-controller rolled back
# 查看发现,通过nginx镜像版本可以发现到了第一版
[root@master ~]# kubectl get deploy -n ingress-nginx -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx-ingress-controller 1/1 1 1 118d nginx-ingress-controller quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0 app.kubernetes.io/name=ingress-nginx,app.kubernetes.io/part-of=ingress-nginx
更多推荐
已为社区贡献3条内容
所有评论(0)