Skip to content

StatefulSet: "updates to statefulset spec … are forbidden" (StorageClass)

Kubernetestested on Rancher v2.15.3, RKE2 v1.36.5, Fleet, Longhorn

Switching the StorageClass in the chart sounds harmless. For a running StatefulSet it is forbidden – even if only an empty field turns into a value.

Symptom

server-side apply failed for object notes/db apps/v1, Kind=StatefulSet: StatefulSet.apps
"db" is invalid: spec: Forbidden: updates to statefulset spec for fields other than
'replicas', 'ordinals', 'template', 'updateStrategy', 'revisionHistoryLimit',
'persistentVolumeClaimRetentionPolicy' and 'minReadySeconds' are forbidden

fleet.yaml sets db.storageClassName: longhorn. After half a minute Fleet reports the error.

Diagnosis

Which StorageClasses exist, which one is the default?

kubectl get sc
local-path           rancher.io/local-path   …
longhorn (default)   driver.longhorn.io      …
longhorn-static      driver.longhorn.io      …

Causes

volumeClaimTemplatesImmutable part of the spec

Only replicas, ordinals, template, updateStrategy and a few more fields may change. The template for PVCs is not one of them.

empty fieldEven "just filling in" counts

In the test it even hit k3s, where local-path was to be set explicitly although it was already in use.

Fix

Write no StorageClass into the chart at all: each cluster takes its default StorageClass. Move existing data via backup.
kubectl annotate sc local-path storageclass.kubernetes.io/is-default-class=false \
  --overwrite
storageclass.storage.k8s.io/local-path annotated

Don't: Deleting the StatefulSet with --cascade=orphan and recreating it without checking what happens to the existing PVCs – the old volumes stay on the old class.

▶
Break it yourself and find it – free
Rancher hands-on, Day 10: installing Longhorn, the default StorageClass, the StatefulSet trap and moving with a backup.
Go to day 10 →

FAQ

Why are two default StorageClasses bad?

Kubernetes then does not choose reliably. Remove the is-default-class annotation from the old class so exactly one default remains.

How do I move an existing volume?

Back up (for example pg_dump), delete the PVC, let it roll out again with the new default class and restore.

Related error patterns

More