StatefulSet pod ordinal in the pod instance label (ss replica ~= app instance)

Hi all,

I have a clustered service, a broker cluster that consists of broker instances. In K8s, the broker cluster is declared as a stateful set with multiple replicas, each replica representing a broker instance.

I need to identify each broker instance. For that, there are recommended labels, namely: A unique name identifying the instance of an application

Is there a way how to declare my intent that the instance label should distinguish the broker instances (represented as replicas) so that K8s would manage the instance label for me, please?

My best understanding is that propagating the pod ordinal to the instance label would help me. So dreaming about an annotation that would be evaluated on pod startup, substitute the pod ordinal, and write the result to


For a stateful set with a pod spec with the = “mars-{{POD_ORDINAL}}” annotation, each time when creating a new pod for a replica, K8s would automatically calculate and set label on the pod.

Stepping back a bit, am I pulling the correct thread?, does it make sense to understand the stateful set replicas as app instances and hence to expect the labels managed in a way to distinguish stateful set replicas, please?

Best regards