I want to create pods with custom ordinal index in stateful set

842 Views Asked by At

Currently when I apply stateful set then pods are getting created with ab-app-0, ab-app-1 , ab-app-2

But I want pods like ab-app-1000, ab-app-1001

2

There are 2 best solutions below

1
viggnah On

The Kubernetes documentation on StatefulSet says the following about ordinal index:

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.

So there looks to be no way of customising this. But if your concern is that you need to pass this unique ID to a service, you could do the following in the config file, as proposed in this open github issue:

        env:
        - name: ZOO_MY_ID
          valueFrom:
            fieldRef:
              fieldPath: metadata.annotations['spec.pod.beta.kubernetes.io/statefulset-index']
0
Helay On

A new feature landed as a beta in v1.27, allowing you to customize the ordinal index .spec.ordinals.start. Please check the official documentation here.