Kubernetes StatefulSet Ordinal Management
Kubernetes StatefulSet Ordinal Management ensures predictable pod identities and ordering through sequential numbering and stable network IDs.
Kubernetes StatefulSet Ordinal Management is the specific mechanics governing how ordinal numbers are assigned, reserved, and maintained as a contiguous range across a StatefulSet's replicas, including the configurable starting ordinal and the strict rules preventing gaps from forming in the sequence during normal scaling operations.
The Default Contiguous Range
Zero-Indexed by Default
Absent any explicit configuration, a StatefulSet's ordinals begin at zero and run contiguously through replicas - 1, so a StatefulSet with replicas: 4 always has exactly the ordinals 0, 1, 2, and 3, never a gap or a number outside that range.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: ordinal-management-example
spec:
replicas: 4
kubectl get pods -l app=web -o custom-columns=NAME:.metadata.name
ordinal-management-example-0
ordinal-management-example-1
ordinal-management-example-2
ordinal-management-example-3
Configuring a Custom Starting Ordinal
spec.ordinals.start
The spec.ordinals.start field allows the sequence to begin at a value other than zero, useful for scenarios such as migrating from an externally numbered system where preserving specific numeric identities matters, or reserving low ordinals for a separate purpose.
spec:
ordinals:
start: 100
replicas: 3
ordinal-management-example-100
ordinal-management-example-101
ordinal-management-example-102
Contiguity Still Enforced From the Start Value
Even with a custom starting ordinal, the range remains strictly contiguous from that starting point; there is no mechanism to declare an arbitrary, non-sequential set of ordinal numbers.
Ordinal Assignment During Scale-Up
Always the Next Sequential Number
When scaling up, the controller always assigns the next number immediately following the current highest ordinal, never filling a gap from an earlier, differently-configured state or skipping ahead arbitrarily.
kubectl scale statefulset ordinal-management-example --replicas=5
The new Pod created is always ordinal-management-example-103 (given the starting ordinal of 100 above), continuing the sequence.
Ordinal Assignment During Scale-Down
Always the Highest Number Removed First
Scaling down always removes the currently highest ordinal, maintaining a contiguous range from the starting value up through the new, lower highest ordinal, never leaving an internal gap.
kubectl scale statefulset ordinal-management-example --replicas=3
This removes ordinal 104 (the highest), returning the set to 100 through 102.
Why Gaps Cannot Persist
The Controller's Reconciliation Guarantees Contiguity
If an intermediate ordinal's Pod is deleted individually, rather than through a coordinated scale-down, the controller detects the gap and recreates that specific missing ordinal to restore the contiguous range, rather than treating the gap as a legitimate reduced state.
kubectl delete pod ordinal-management-example-101
kubectl get pods -l app=web
ordinal-management-example-100
ordinal-management-example-101 # recreated, not skipped
ordinal-management-example-102
Practical Implications for Capacity Planning
Ordinal Count Directly Reflects Replica Count
Because ordinals are always contiguous, the total ordinal range at any moment is a direct, unambiguous indicator of current replica count, useful for capacity dashboards and automation that need to reason about "how many stateful instances currently exist" without any additional bookkeeping.
Ordinal Management Diagram
Understanding this strict contiguity guarantee is what allows automation and monitoring built on top of stateful workloads to trust ordinal numbers as a reliable, gap-free index into the current set of running instances at any point in time.