ArgoCD: deployment spec.selector: field is immutable
• 124 words • 1 min • updated
⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.
When using ArgoCD to manage an app, the Deployment manifest needs to undergo significant changes, updating its selector labels. When trying to sync the argocd app, we get the following error:
one or more objects failed to apply, reason: error when patching "/dev/shm/3469418025": Deployment.apps "myapp" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:v1.LabelSelectorRequirement(nil)}: field is immutable. Retrying attempt #2 at 11:02AM.This error doesn’t come directly from Argo, it is from kubectl apply.
There are two ways to address it:
-
Sync the argo app with the “force” option enabled
-
Run
kubectl applywith--force(which is ultimately what the aforementioned option maps to).
In action (-w is short for --watch):
% kubectl get endpoints -w
NAME ENDPOINTS AGE
myapp <none> 5y44d
myapp 5y44d
myapp 10.1.13.40:8080 5y44d