StatefulSet identity
Why a replica needs a name
A Deployment works well when any replica can serve a request. Suppose a small ledger service has separate local records for three members. The member called ledger-1 must find its own previous data after replacement, rather than take whatever disk is available. A StatefulSet assigns each member an ordinal (a numeric position) and associates that position with a Pod name. Use it when stable membership, persistent per-member storage or controlled ordering is a genuine application requirement. A StatefulSet does not implement the ledger protocol.
A stable address for each member
apiVersion: v1kind: Servicemetadata: name: ledger-peer namespace: ledger-studyspec: clusterIP: None selector: app.kubernetes.io/name: ledger ports: - name: peer port: 8080 targetPort: peerStatic Service example from ledger.yaml. A headless Service has no virtual ClusterIP. It supports discovery of individual matching Pods. The Service and StatefulSet belong to ledger-study. The controller refers to this Service through serviceName; create the Service separately. The assumed cluster domain is cluster.local, not a universal setting.
Read the identity mapping
With the normal starting ordinal of zero, three members are ledger-0, ledger-1 and ledger-2. The assumed fully qualified name for member 1 is ledger-1.ledger-peer.ledger-study.svc.cluster.local. For ready endpoints and working cluster DNS, the name can resolve to the member’s current address. DNS caching can delay discovery. An unready member might not be published; do not enable publication of unready endpoints without an application-specific reason.
A replacement is still a new Pod
{ "before": { "pod": "ledger-1", "uid": "synthetic-old", "ip": "192.0.2.21", "claim": "data-ledger-1" }, "after": { "pod": "ledger-1", "uid": "synthetic-new", "ip": "192.0.2.52", "claim": "data-ledger-1" }}The invented snapshots show the same member name and claim, but different UID and IP. Stable identity is not a permanent network address, and it does not mean the same Pod object is immortal. Check the actual claim binding and application data before concluding that recovery succeeded.
Choosing a workload controller
Use a Deployment for interchangeable catalog HTTP workers. Consider a StatefulSet for members that require individual disk ownership and stable names. A database may also need leader election, replication, fencing and consistent backups, which are outside the controller’s contract. Do not confuse a replica count of three with three copies of the same records.
Practice
In identity.json, predict the name of member 2 and its DNS name. Explain which fields could change after a normal replacement. Check the matching labels and serviceName in ledger.yaml. This is a static manifest reading exercise, not a live DNS test.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
StatefulSet identity — knowledge check
Apply the chapter concepts using synthetic offline scenarios.
What stays the same when ledger-1 is normally replaced?
Which Service setting removes the virtual ClusterIP?
With three replicas starting at zero, what is the highest ordinal?
What does a StatefulSet not implement for an application?
Why should a client avoid storing an individual Pod IP permanently?