一、滚动更新
1、将myapp控制器下的pod资源镜像升级为:"ikubernetes/myapp:v6"
[root@master ~]# kubectl set image sts myapp myapp=ikubernetes/myapp:v6 statefulset.apps/myapp image updated
2、实时监控更新操作过程
[root@master chapter9]# kubectl get pods -l app=myapp-pod -w NAME READY STATUS RESTARTS AGE myapp-0 1/1 Running 0 39s myapp-1 1/1 Running 0 36s myapp-2 1/1 Running 0 34s myapp-2 1/1 Terminating 0 38s myapp-2 0/1 Terminating 0 40s myapp-2 0/1 Terminating 0 49s myapp-2 0/1 Terminating 0 49s myapp-2 0/1 Pending 0 0s myapp-2 0/1 Pending 0 0s myapp-2 0/1 ContainerCreating 0 0s myapp-2 1/1 Running 0 2s myapp-1 1/1 Terminating 0 53s myapp-1 0/1 Terminating 0 55s myapp-1 0/1 Terminating 0 56s myapp-1 0/1 Terminating 0 56s myapp-1 0/1 Pending 0 0s myapp-1 0/1 Pending 0 0s myapp-1 0/1 ContainerCreating 0 0s myapp-1 1/1 Running 0 2s myapp-0 1/1 Terminating 0 61s myapp-0 0/1 Terminating 0 62s myapp-0 0/1 Terminating 0 63s myapp-0 0/1 Terminating 0 63s myapp-0 0/1 Pending 0 0s myapp-0 0/1 Pending 0 0s myapp-0 0/1 ContainerCreating 0 0s myapp-0 1/1 Running 0 3s
3、验证更新是否生效
[root@master ~]# for i in 0 1 2; do kubectl get po myapp-$i --template '{{range $i,$c := .spec.containers}}{{$c.image}}{{end}}';echo; done ikubernetes/myapp:v6 ikubernetes/myapp:v6 ikubernetes/myapp:v6
另外、用户也可使用""命令跟踪statefulset资源滚动更新过程中的状态信息
二、暂存更新操作
1、暂存更新
[root@master ~]# kubectl patch statefulset myapp -p '{"spec":{"updateStrategy":{"rollingUpdate":{"partition":3}}}}' statefulset.apps/myapp patched
2、而后、更新myapp控制器的pod资源镜像版本更新为:"ikubernetes/myapp:v7"
[root@master ~]# kubectl set image sts myapp myapp=ikubernetes/myapp:v7 statefulset.apps/myapp image updated
3、接着检测各POD资源的镜像文件版本信息、可以发现其版本并为发生改变
[root@master ~]# for i in 0 1 2; do kubectl get po myapp-$i --template '{{range $i,$c := .spec.containers}}{{$c.image}}{{end}}';echo; done ikubernetes/myapp:v6 ikubernetes/myapp:v6 ikubernetes/myapp:v6
删除了pod对象myapp-1、随后待其重建操作启动后、再获取与其相关的镜像信息、结果依然显示了旧的版本
[root@master ~]# kubectl delete pod myapp-1 pod "myapp-1" deleted [root@master ~]# kubectl get pods myapp-1 -o custom-columns=NAME:metadata.name,IMAGE:spec.containers[0].image NAME IMAGE myapp-1 ikubernetes/myapp:v6
由此可见、暂存状态的更新操作对所有的pod资源均不产生影响
三、金丝雀部署
1、更新分区myapp-2 的镜像为:"ikubernetes/myapp:v7"
[root@master ~]# kubectl patch statefulset myapp -p '{"spec":{"updateStrategy":{"rollingUpdate":{"partition":2}}}}' statefulset.apps/myapp patched
2、验证版本是否生效
[root@master ~]# kubectl get pods -l app=myapp-pod -o custom-columns=NAME:metadata.name,IMAGE:spec.containers[0].image NAME IMAGE myapp-0 ikubernetes/myapp:v6 myapp-1 ikubernetes/myapp:v6 myapp-2 ikubernetes/myapp:v7