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

Amit Yadav

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?

Oleg Butuzov

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Configure starting index of StatefulSet's pods in Kubernetes

Kubernetes pods not starting, running behind a proxy

Set retention policy for Pods created by Kubernetes CronJob

Why Kubernetes Services are created before Deployment/Pods?

Is a Kubernetes StatefulSet the right answer if all we need is a consistent identifier for each Pod in a group of identical Pods?

Kubernetes multiple pvc with statefulset for each pod vs single pvc for all pods?

Ping pods of a statefulset via DNS

StatefulSet update: recreate THEN delete pods

Kubernetes : Multiple pods result in a scheduler being invoked multiple times

How to configure Kubernetes to encrypt the traffic between nodes, and pods?

Kubernetes pods failing on "Pod sandbox changed, it will be killed and re-created"

Adding Hospath to a Kubernetes Statefulset

Helm / Kubernetes - Statefulset & Permissions

kubernetes creating statefulset fail

Kubernetes Admission webhook for Statefulset

apply HPA for Statefulset in kubernetes?

kubernetes - How to ensure running pods are terminated before new pods are created for a deployment

How to initiate an index for an object being created in React?

How to expose the scale of a deployment or statefulset to the pods in it?

Running DB as Kubernetes Deployment or StatefulSet?

StatefulSet volume mounts for OrientDB in Kubernetes

cant run mysql statefulset in kubernetes

Redeploy statefulset with CrashLoopBackOff status in kubernetes

How to sync a folder in kubernetes statefulset

"UnknownHostException": Zookeeper 3.5.3 and StatefulSet Kubernetes

Kubernetes trouble with StatefulSet and 3 PersistentVolumes

Kubernetes mysql statefulset with root password

How to set pvc with statefulset in kubernetes?

Error on StatefulSet creation for mongodb on Kubernetes