在 Kubernetes 中配置 StatefulSet 的 pods 起始索引
Configure starting index of StatefulSet's pods in Kubernetes
众所周知documentation:
For a StatefulSet with N replicas, each Pod in the StatefulSet will be assigned an integer ordinal, from 0 up through N-1, that is unique over the Set.
示例:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: zookeeper-np
labels:
app: zookeeper-np
spec:
serviceName: zoo-svc-np
replicas: 3
selector:
matchLabels:
app: zookeeper-np
template:
metadata:
labels:
app: zookeeper-np
spec:
containers:
- name: zookeeper-np
image: zookeeper:3.5.6
ports:
- containerPort: 30005
- containerPort: 30006
- containerPort: 30007
env:
- name: ZOO_MY_ID
value: "1"
上面的清单将创建三个 pods,如下所示:
NAME READY STATUS STARTS AGE
pod/zookeeper-np-0 1/1 Running 0 203s
pod/zookeeper-np-1 1/1 Running 0 137s
pod/zookeeper-np-2 1/1 Running 0 73s
问题:
有没有办法将此起始索引 (0) 配置为从任何其他整数(例如 1、2、3 等)开始?
例如,要从 3 开始上述 pod 索引,这样创建的 pods 将如下所示:
NAME READY STATUS STARTS AGE
pod/zookeeper-np-3 1/1 Running 0 203s
pod/zookeeper-np-4 1/1 Running 0 137s
pod/zookeeper-np-5 1/1 Running 0 73s
或者如果statefulset只有一个replica,它的序数不是零而是其他一些整数(例如12),所以创建的唯一pod将被命名为pod/zookeeper-np-12?
不幸的是,根据source code 0...n 只是副本切片的切片索引,这是不可能的。查看 newVersionedStatefulSetPod
的最后一个参数
众所周知documentation:
For a StatefulSet with N replicas, each Pod in the StatefulSet will be assigned an integer ordinal, from 0 up through N-1, that is unique over the Set.
示例:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: zookeeper-np
labels:
app: zookeeper-np
spec:
serviceName: zoo-svc-np
replicas: 3
selector:
matchLabels:
app: zookeeper-np
template:
metadata:
labels:
app: zookeeper-np
spec:
containers:
- name: zookeeper-np
image: zookeeper:3.5.6
ports:
- containerPort: 30005
- containerPort: 30006
- containerPort: 30007
env:
- name: ZOO_MY_ID
value: "1"
上面的清单将创建三个 pods,如下所示:
NAME READY STATUS STARTS AGE
pod/zookeeper-np-0 1/1 Running 0 203s
pod/zookeeper-np-1 1/1 Running 0 137s
pod/zookeeper-np-2 1/1 Running 0 73s
问题:
有没有办法将此起始索引 (0) 配置为从任何其他整数(例如 1、2、3 等)开始?
例如,要从 3 开始上述 pod 索引,这样创建的 pods 将如下所示:
NAME READY STATUS STARTS AGE
pod/zookeeper-np-3 1/1 Running 0 203s
pod/zookeeper-np-4 1/1 Running 0 137s
pod/zookeeper-np-5 1/1 Running 0 73s
或者如果statefulset只有一个replica,它的序数不是零而是其他一些整数(例如12),所以创建的唯一pod将被命名为pod/zookeeper-np-12?
不幸的是,根据source code 0...n 只是副本切片的切片索引,这是不可能的。查看 newVersionedStatefulSetPod