Skip to content

Field is immutable

Some fields can’t be changed after an object is created. The API server rejects the update and names the field.

Object Field Why
Deployment, StatefulSet, DaemonSet spec.selector Defines which pods the controller owns
Job spec.template (mostly) A Job runs a fixed template to completion
Service spec.clusterIP Clients may have cached the IP
PersistentVolumeClaim Most of spec, except storage size (expansion) The volume already exists
StatefulSet volumeClaimTemplates PVCs were already created from it

Keep immutable fields stable across releases, and add new labels to the pod template instead of the selector. When you really must change one:

  • Job: delete and recreate it. Delete completed Jobs in your pipeline, or use ttlSecondsAfterFinished.
  • Deployment selector: create a new Deployment with a new name, move traffic, then delete the old one.
  • StatefulSet volumeClaimTemplates: delete the StatefulSet with --cascade=orphan (pods and PVCs keep running) and recreate it with the new template.

kubectl replace --force deletes and recreates the object. For a Deployment, that means downtime.