✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes StatefulSet Pod Template Management

Kubernetes StatefulSet Pod Template Management governs how stateful applications are consistently deployed and updated in a Kubernetes cluster.

Kubernetes StatefulSet Pod Template Management is the practice of editing a StatefulSet's spec.template with awareness of its slower, ordered propagation compared to a Deployment, and the separate, more restrictive rules governing changes to volumeClaimTemplates, which do not retroactively affect already-provisioned storage the way a template change affects Pod content.


Propagation Is Ordered, Not Parallel

One Ordinal at a Time by Default

Unlike a Deployment's typically parallel rollout, a template change to a StatefulSet propagates through Pods one ordinal at a time under the default OrderedReady management policy, meaning the total time to fully apply a change scales linearly with replica count, a planning consideration absent from stateless template management.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: pod-template-management-example
spec:
  template:
    spec:
      containers:
        - name: db
          image: registry.example.com/db:2.0.0
kubectl rollout status statefulset/pod-template-management-example

Using Partition to Test Before Wide Propagation

Validating on the Highest Ordinal First

Because propagation proceeds from the highest ordinal downward, setting partition to the current replica count minus one restricts a template change to affect only the topmost ordinal initially, letting it serve as a canary before lowering the partition to extend the change further.

spec:
  updateStrategy:
    rollingUpdate:
      partition: 2
kubectl patch statefulset pod-template-management-example -p '{"spec":{"updateStrategy":{"rollingUpdate":{"partition":1}}}}'

volumeClaimTemplates Are Not Retroactive

Changes Only Affect Newly Provisioned Claims

Editing spec.volumeClaimTemplates after a StatefulSet has already provisioned claims for its existing ordinals has no effect on those already-existing PersistentVolumeClaims; the template only governs claims created for new ordinals introduced by a subsequent scale-up.

spec:
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        resources:
          requests:
            storage: 100Gi

Existing ordinals with a claim already provisioned at 50Gi remain at 50Gi despite this template now specifying 100Gi.

Resizing Existing Storage Requires a Separate Path

Growing storage for already-provisioned ordinals requires editing the individual PersistentVolumeClaim objects directly (where the StorageClass supports volume expansion), a distinct operation from any StatefulSet template edit, and must be performed once per existing claim rather than through the template mechanism.

kubectl patch pvc data-pod-template-management-example-0 -p '{"spec":{"resources":{"requests":{"storage":"100Gi"}}}}'

Immutable Fields Within volumeClaimTemplates

What Cannot Be Changed After Initial Provisioning

Certain fields within an already-referenced volumeClaimTemplates entry, notably accessModes and, in most cases, storageClassName, cannot be meaningfully changed for existing claims regardless of what the template now specifies, since the underlying PersistentVolume binding was established at original provisioning time.


Coordinating Container Changes With Data Format Changes

Sequencing Schema-Sensitive Updates

Where a new container image also requires a data format or schema change on disk, template management practice sequences this carefully using the partition mechanism, verifying the new image handles the existing on-disk format correctly on a single ordinal before the change reaches ordinals holding the bulk of the data.


StatefulSet Template Management Diagram

Container template change → propagates ordinal by ordinal volumeClaimTemplates change → only affects new ordinals

Recognizing that container template changes and storage template changes follow entirely different propagation rules is essential for stateful workload changes involving both, since assuming uniform behavior across the two risks either an unexpectedly slow rollout or an unexpectedly absent storage change.