现在我们修改yaml文件,将image修改为nginx:alpine 执行更新,运行如下
[root@qd01-stop-k8s-master001 demo]# kubectl get po -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |sort nginx-2-7lzx9: nginx:1.18.0, nginx-2-b5fdd: nginx:1.18.0, nginx-2-jw2zp: nginx:1.18.0, nginx-2-l54dz: nginx:1.18.0, nginx-2-nknrt: nginx:alpine, nginx-2-rgmsc: nginx:alpine, nginx-2-rpr5z: nginx:alpine, nginx-2-t49mk: nginx:1.18.0, nginx-2-v2bpx: nginx:alpine, nginx-2-zpp8z: nginx:1.18.0,现在看到,有4个pod的image已经更新为nginx:alpine 然后我们再次修改yaml文件,添加paused: true
spec: replicas: 10 updateStrategy: paused: true type: InPlaceIfPossible inPlaceUpdateStrategy: gracePeriodSeconds: 10再次执行apply,更新yaml,再次查看更新进度,发现pod并没有继续更新了,已经暂停升级image了
[root@qd01-stop-k8s-master001 demo]# kubectl get po -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |sort nginx-2-7lzx9: nginx:1.18.0, nginx-2-b5fdd: nginx:1.18.0, nginx-2-jw2zp: nginx:1.18.0, nginx-2-l54dz: nginx:1.18.0, nginx-2-nknrt: nginx:alpine, nginx-2-rgmsc: nginx:alpine, nginx-2-rpr5z: nginx:alpine, nginx-2-t49mk: nginx:1.18.0, nginx-2-v2bpx: nginx:alpine, nginx-2-zpp8z: nginx:1.18.0,最后把paused: true取消,再次apply yaml文件,升级会继续。。。
[root@qd01-stop-k8s-master001 demo]# kubectl get po -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |sort nginx-2-7lzx9: nginx:alpine, nginx-2-b5fdd: nginx:alpine, nginx-2-jw2zp: nginx:alpine, nginx-2-l54dz: nginx:alpine, nginx-2-nknrt: nginx:alpine, nginx-2-rgmsc: nginx:alpine, nginx-2-rpr5z: nginx:alpine, nginx-2-t49mk: nginx:alpine, nginx-2-v2bpx: nginx:alpine, nginx-2-zpp8z: nginx:alpine,以上就是整个发布暂停的演示,这个功能好处就是;我们在升级的过程中可以随时中断升级。
除此之外,CloneSet还有很多特性,例如:MaxUnavailable 最大不可用数量、MaxSurge 最大弹性数量、升级顺序、打散策略、生命周期钩子等,鉴于文章篇幅,这些特性不再演示了,有需要的可以查看官方文档。