I want to access the number of replicas and also the current replica id for a given pod, from inside the pod itself. For example, if there are 3 replicas of any given pod, say foo_A, foo_B and foo_C, created in that specific order, is it possible to have total number of replicas and index of pod within the replica set to be available within the pod ?
Also I understand that, with old pods getting killed and new ones coming up, index of pod within replica set can dynamically change.
I know this can be achieved using Downward API, but which fields to access ? Could anyone please help ?
As mentioned in comments, you can use StatefulSets:
As you can see here your pods will be created in a ordinal sequence: