An ordinal index is an incrementing integer that identifies a Pod’s stable position in a StatefulSet: 0, 1, 2, and so on. Unlike Deployment Pods, which receive new random names after replacement, a recreated StatefulSet Pod retains its ordinal and attached identity. section 9.2.1
The ordinal makes individual Pods addressable. A Pod can be reached through the pattern STATEFULSET_NAME-POD_ORDINAL.SERVICE_NAME, such as mariadb-0.mariadb-service. This depends on the stable network identities provided by a headless Service. section 9.2.1
Stateful applications use the ordinal to:
- Preserve a Pod’s position when disruption causes it to be recreated. section 9.2.1
- Associate a Pod with its stable network name and persistent disk. section 9.2.2
- Assign different roles to Pods according to their position in the set. section 9.2.2
Assigning Redis roles
A three-Pod Redis StatefulSet uses ordinal 0 for the primary Pod and assigns the replica role to other ordinals. An init container extracts the ordinal from the hostname, then copies primary.conf for ordinal 0 or replica.conf for every other Pod. Redis replicas therefore reference redis-0.redis-service as their primary. section 9.2.2
