Kubernetes StatefulSet 扩缩容与升级
StatefulSet 扩容
kubectl scale sts stateful-set-web --replicas=5
root@k8s-master1:~# kubectl get pods --watch -l app=pod-nginx
NAME READY STATUS RESTARTS AGE
stateful-set-web-0 1/1 Running 0 7h23m
stateful-set-web-1 1/1 Running 0 7h23m
stateful-set-web-2 0/1 Pending 0 0s
stateful-set-web-2 0/1 Pending 0 0s
stateful-set-web-2 0/1 Pending 0 2s
stateful-set-web-2 0/1 ContainerCreating 0 2s
stateful-set-web-2 0/1 ContainerCreating 0 2s
stateful-set-web-2 1/1 Running 0 3s
stateful-set-web-3 0/1 Pending 0 0s
stateful-set-web-3 0/1 Pending 0 0s
stateful-set-web-3 0/1 Pending 0 2s
stateful-set-web-3 0/1 ContainerCreating 0 2s
stateful-set-web-3 0/1 ContainerCreating 0 2s
stateful-set-web-3 1/1 Running 0 3s
stateful-set-web-4 0/1 Pending 0 0s
stateful-set-web-4 0/1 Pending 0 0s
stateful-set-web-4 0/1 Pending 0 2s
stateful-set-web-4 0/1 ContainerCreating 0 2s
stateful-set-web-4 0/1 ContainerCreating 0 2s
stateful-set-web-4 1/1 Running 0 2s
StatefulSet 缩容
kubectl patch sts stateful-set-web -p '{"spec":{"replicas":3}}'
root@k8s-master1:~# kubectl get pods --watch -l app=pod-nginx
NAME READY STATUS RESTARTS AGE
stateful-set-web-0 1/1 Running 0 9h
stateful-set-web-1 1/1 Running 0 9h
stateful-set-web-2 1/1 Running 0 107m
stateful-set-web-3 1/1 Running 0 107m
stateful-set-web-4 1/1 Running 0 107m
stateful-set-web-4 1/1 Terminating 0 107m
stateful-set-web-4 1/1 Terminating 0 107m
stateful-set-web-4 0/1 Terminating 0 107m
stateful-set-web-4 0/1 Terminating 0 107m
stateful-set-web-4 0/1 Terminating 0 107m
stateful-set-web-4 0/1 Terminating 0 107m
stateful-set-web-3 1/1 Terminating 0 107m
stateful-set-web-3 1/1 Terminating 0 107m
stateful-set-web-3 0/1 Terminating 0 107m
stateful-set-web-3 0/1 Terminating 0 107m
stateful-set-web-3 0/1 Terminating 0 107m
stateful-set-web-3 0/1 Terminating 0 107m
StatefulSet 更新
RollingUpdate 定义与使用
滚动更新将会以倒叙的方式逐次更新 Pod , 同时我们也可以用partition
字段来分割更新部分与不更新部分。假设partition
为2,副本数为3,则副本索引为 0,1,2。即更新部分为副本数(3-1)至 2,索引 2 更新;不更新部分索引 0 和 1。
kubectl patch statefulset stateful-set-web --type='json' -p='[{"op":
"replace", "path": "/spec/template/spec/containers/0/image", "value":"registry.k8s.io/ngi
nx-slim:0.7"}]'
root@k8s-master1:~# kubectl get pods --watch -l app=pod-nginx
NAME READY STATUS RESTARTS AGE
stateful-set-web-0 1/1 Running 0 9h
stateful-set-web-1 1/1 Running 0 9h
stateful-set-web-2 1/1 Running 0 112m
stateful-set-web-2 1/1 Terminating 0 122m
stateful-set-web-2 1/1 Terminating 0 122m
stateful-set-web-2 0/1 Terminating 0 122m
stateful-set-web-2 0/1 Terminating 0 122m
stateful-set-web-2 0/1 Terminating 0 122m
stateful-set-web-2 0/1 Terminating 0 122m
stateful-set-web-2 0/1 Pending 0 0s
stateful-set-web-2 0/1 Pending 0 0s
stateful-set-web-2 0/1 ContainerCreating 0 0s
stateful-set-web-2 0/1 ContainerCreating 0 1s
stateful-set-web-2 1/1 Running 0 8s
stateful-set-web-1 1/1 Terminating 0 9h
stateful-set-web-1 1/1 Terminating 0 9h
stateful-set-web-1 0/1 Terminating 0 9h
stateful-set-web-1 0/1 Terminating 0 9h
stateful-set-web-1 0/1 Terminating 0 9h
stateful-set-web-1 0/1 Terminating 0 9h
stateful-set-web-1 0/1 Pending 0 0s
stateful-set-web-1 0/1 Pending 0 0s
stateful-set-web-1 0/1 ContainerCreating 0 0s
stateful-set-web-1 0/1 ContainerCreating 0 1s
stateful-set-web-1 1/1 Running 0 5s
stateful-set-web-0 1/1 Terminating 0 9h
stateful-set-web-0 1/1 Terminating 0 9h
stateful-set-web-0 0/1 Terminating 0 9h
stateful-set-web-0 0/1 Terminating 0 9h
stateful-set-web-0 0/1 Terminating 0 9h
stateful-set-web-0 0/1 Terminating 0 9h
stateful-set-web-0 0/1 Pending 0 0s
stateful-set-web-0 0/1 Pending 0 0s
stateful-set-web-0 0/1 ContainerCreating 0 0s
stateful-set-web-0 0/1 ContainerCreating 0 0s
stateful-set-web-0 1/1 Running 0 0s
OnDelete 定义与使用
OnDelete 指的是不直接更新 Pod,只有在 Pod 被删除后才会被更新。
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"OnDelete"}}}'
标签:web,set,Terminating,Kubernetes,0s,扩缩容,stateful,StatefulSet,9h
From: https://blog.csdn.net/baidu_34688878/article/details/139332601