StatefulSet扩缩容源码分析
k8s v1.15.0
Informer监听
cmd/kube-controller-manager/app/apps.go
作为StatefulSet资源控制器,StatefulSetController通过PodInformer、StatefulSetInformer、PersistentVolumeClaimInformer、ControllerRevisionInformer来监听事件。
StatefulSet Controller通过resync来同步丢失的事件,同步时间是[12h, 24h)随机值,其他controller也是如此。
扩缩容StatefulSet
podManagementPolicy
Parallel
并行创建或者删除Pod
pkg/controller/statefulset/stateful_set_control.go
updateStatefulSet方法
monotonic判断是否为并行管理策略
Parallel场景并行创建Pod
收集需要删除的Pod
Parallel场景并行删除Pod
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- port: 80
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx
spec:
podManagementPolicy: Parallel
serviceName: nginx
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.9.1