Set custom oridinal number for pod in kubernetes statefulset not the default 0

7/26/2019

In Kubernetes statefulset, ordinal number starts with 0 --> N. Is there any way that starting ordinal number can be set to custom number.

redis-cluster-10   1/1     Running   0          12h
redis-cluster-11   1/1     Running   2          17h
redis-cluster-12   1/1     Running   0          17h
redis-cluster-13   1/1     Running   0          17h
redis-cluster-14   1/1     Running   2          17h
redis-cluster-15   1/1     Running   0          17h
-- Jatinder Jawanda
kubernetes
kubernetes-statefulset

2 Answers

7/26/2019

no. it is not supported out of box.you might have to customize the statefulset controller.

-- P Ekambaram
Source: StackOverflow

7/26/2019

I think this is the part that might be of interest to you:

https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/statefulset/stateful_set_utils.go

// getParentNameAndOrdinal gets the name of pod's parent StatefulSet and pod's ordinal as extracted from its Name. If
// the Pod was not created by a StatefulSet, its parent is considered to be empty string, and its ordinal is considered
// to be -1.
func getParentNameAndOrdinal(pod *v1.Pod) (string, int) {
    parent := ""
    ordinal := -1
    subMatches := statefulPodRegex.FindStringSubmatch(pod.Name)
    if len(subMatches) < 3 {
        return parent, ordinal
    }
    parent = subMatches[1]
    if i, err := strconv.ParseInt(subMatches[2], 10, 32); err == nil {
        ordinal = int(i)
    }
    return parent, ordinal
}
-- Crou
Source: StackOverflow