Configure the starting index of pods being created by a StatefulSet in kubernetes

12/12/2019

As we all know from the 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.

Example:

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"

The above manifest will create three pods like below:

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

Question:

Is there a way to configure this starting index (0) to start from any other integer (e.g 1,2,3 etc.)?

For example, to start the above pod indices from 3 so that the pods created will look like something below:

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

Or if there is only one replica of the statefulset, its ordinal is not zero but some other integer (e.g 12), so that the only pod created will be named as pod/zookeeper-np-12?

-- Amit Yadav
kubernetes
kubernetes-statefulset

1 Answer

12/12/2019

Unfortunately, it's impossible, according to source code 0...n is just slice index of replicas slice. See the last argument to newVersionedStatefulSetPod

-- Oleg Butuzov
Source: StackOverflow