6

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
  • 4,422
  • 5
  • 34
  • 79

1 Answers1

8

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
  • 4,795
  • 2
  • 24
  • 33
  • Is there any way to configure the pod name in case there is only one replica? I am looking for this because deploying [incubator/kafka](https://github.com/helm/charts/tree/master/incubator/kafka) Helm chart configures the brokerID from the last letter of the pod-name. See [here](https://github.com/helm/charts/blob/cc7e5d7aeb78a85f3b73d1e1229196d0334de4a4/incubator/kafka/templates/statefulset.yaml#L201). Is there any way to somehow change the last digit of the pod name in order to manually configure the broker ID? – Amit Yadav Dec 13 '19 at 10:05
  • 1
    StatefulSets will have a number at the end. No matter fo what, that's how they work. I think it's better to raise an issue on Kafka chart and provide solution on it. – Oleg Butuzov Dec 13 '19 at 10:11
  • I get that. Makes sense. I will edit the question and add the link to the issue once created. – Amit Yadav Dec 13 '19 at 10:33