再赶快查看一下滚动发布的状态:
$ kubectl rollout status deployment my-first-demo-dep Waiting for rollout to finish: 1 old replicas are pending termination... deployment "my-first-demo-dep" successfully rolled out如上命令所表示,随着最后一个old replicas 终止,新版本的deployment成功发布了successfully rolled out。
简直是太激动了,验证一下是不是3个pod,如下,没问题,3个Running状态。
$ kubectl get pods NAME READY STATUS RESTARTS AGE my-first-demo-dep-54596847d8-6m4n9 1/1 Running 0 36s my-first-demo-dep-54596847d8-jrm8g 1/1 Running 0 38s my-first-demo-dep-54596847d8-nqgmn 1/1 Running 0 34s访问一下看看:
$ curl 'http://localhost:30000/' <h1>Hello worldls , this is Version 2.</h1>已经是新版本了,可惜啊,新版本有问题啊!单词拼错了,world写成了worldls,我们来赶紧回滚一下。
Kubenetes应用集群回滚上面我们使用滚动发布,将网站升级为version2了。但是有错误,我们来查看一下发布历史:
$ kubectl rollout history deployment my-first-demo-dep deployment.extensions/my-first-demo-dep REVISION CHANGE-CAUSE 1 kubectl apply --filename=dep.yml --record=true 2 kubectl apply --filename=dep.yml --record=true可以看到,有两个版本,我们回滚到版本1,执行如下命令:
$ kubectl rollout undo deployment my-first-demo-dep --to-revision=1 deployment.extensions/my-first-demo-dep rolled back查看回滚过程状态:
$ kubectl rollout status deployment my-first-demo-dep Waiting for deployment "my-first-demo-dep" rollout to finish: 2 out of 3 new replicas have been updated... Waiting for deployment "my-first-demo-dep" rollout to finish: 2 out of 3 new replicas have been updated... Waiting for deployment "my-first-demo-dep" rollout to finish: 2 out of 3 new replicas have been updated... Waiting for deployment "my-first-demo-dep" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "my-first-demo-dep" rollout to finish: 1 old replicas are pending termination... deployment "my-first-demo-dep" successfully rolled out上面的日志显示了完整的回滚过程,看到最后一行successfully rolled out输出的时候,说明回滚完成了。这时候响应的应该就是 Hello world!,我们来验证一下回滚效果:
$ curl 'http://localhost:30000/' <h1>Hello world! <h1>OK,成功了,回滚到了没有错误的原始版本。
总结本篇演示了Kubenetes集群发布,集群副本集查看,集群自愈能力演示,集群扩容,滚动升级,以及回滚。然而这一切来得是如此的简单,我们只需要修改一下配置,执行一个命令,剩下的工作Kubenetes都帮我们做了。当我在回顾我几年前所在的某家公司的时候,程序升级上线都是由运维手工完成,虽然也完成了任务,但是那种原始的操作方式,在时下如果还有人用的话,那简直是不敢想象。
Docker & k8s 系列一:快速上手docker
Docker & k8s 系列二:本机k8s环境搭建
Docker & k8s 系列三:在k8s中部署单个服务实例