You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Upgrade fails when deployment.spect.template has a chart label #2494
I'm not sure why this is happening. I went ahead and added a chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" to a Deployment's spec.template.metadata.labels. I upgraded the chart, and got this error:
Error: UPGRADE FAILED: Deployment.extensions "test-demo" is invalid: spec.template.metadata.labels: Invalid value: {"app":"test-demo","chart":"demo-0.1.1"}: `selector` does not match template `labels`
It seems that this label should not be applied to a deployment template?
helm init demo
helm install --release test demo/
# add to the deployment's spect template labels: chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
# bump the version
helm upgrade test demo/
Suggestion
I'm guessing that helm expects certain labels for anything in the chart. There are also cases were labels must not be present. helm lint should cover this.
.spec.selector is an optional field that specifies a label selector for the Pods targeted by this deployment.
If specified, .spec.selector must match .spec.template.metadata.labels, or it will be rejected by the API. If .spec.selector is unspecified, .spec.selector.matchLabels will be defaulted to .spec.template.metadata.labels.
I take it you have a .spec.selector in your Deployment.
Reacted by tobe, sysC0D, Prasanna kumar Krishnamurthy, Yun Zhao, Sean Turner, Nikhil-Danaher and s_yasunaga
Just for future reference I ran into this because I was adding chart: "{{.Chart.Name}}-{{.Chart.Version}}" as .spec.template.metadata.labels which would also become .spec.selector.matchLabels after the first release. On the second release if I bumped the version number, I'd get the above error (since .spec.selector.matchLabels and .spec.template.metadata.labels would now be different). Removing the chart label from .spec.template.metadata.labels and only using it in .metadata.labels seems to make it work normally.
Reacted by George Antoniadis, Danny Krainas, Mateusz Zakarczemny, Adam Barthelson, Prasanna kumar Krishnamurthy, Yun Zhao, Joe Kamibeppu, Are Almaas, Robin Kearney, Ryan Roden-Corrent and 7 more
I have this situation in a production deployment. Is there a combination of steps I can perform to change the .spec.selector along with the .spec.template.metadata.labels to fix this?
deployment spec selectors are no longer mutable as of apps/v1beta2 and this is noted upstream in kubernetes/kubernetes#50719. Short of helm delete --purge myrelease and running helm install again on your chart, there is no way to mutate the selector labels.
Short of helm delete --purge myrelease and running helm install again on your chart, there is no way to mutate the selector labels.
Is --purge overkill? I'm not sure how wiping out your release history would help -- just deleting should remove the deployment and reset helm's internal state.
What is the official recommendation from Helm for Deployments regarding this issue? Simply removing .spec.selector.matchLabels? Deleting/recreating a Release or part of it during an upgrade is NOT an option in production, and --force would break any RollingUpdate.
Not sure this is "official" but what I did was describe the deployments that were failing then I hand edited the chart to make the labels static. That way when helm upgrades the charts those items are not seen as changed.
And I learned from this not to put dynamic data in labels.
It has been about 6 months and the best practices still recommend a chart label.
I'm seeing a lot of teams shooting themselves in the foot with this. You create a chart, deploy it successfully, everything seems fine. Then later on you try to upgrade and realize your only option is to delete --purge and incur downtime.
@rcorre I do think you can manually fix the issue. It's not what Helm should force you to do, but it is a workaround.
You can remove the deployment/replicaset (without cascading, keeping the pods alive), then update the pods labels (and anything that depends on them, like services) then redeploy. The new deployment should recognize those same pods as up already. If not, the new deployment should go live and you can manually remove the old pods with no downtime.
I believe a teammate of mine did this successfully, but I'd definitely recommend testing it out first 🙂
Edit: See below for a proven method
Activity
seh commentedon May 25, 2017
This is a restriction in Kubernetes itself, unrelated to Helm:
I take it you have a
.spec.selectorin your Deployment.mikesplain commentedon Jun 28, 2017
Just for future reference I ran into this because I was adding
chart: "{{.Chart.Name}}-{{.Chart.Version}}"as.spec.template.metadata.labelswhich would also become.spec.selector.matchLabelsafter the first release. On the second release if I bumped the version number, I'd get the above error (since.spec.selector.matchLabelsand.spec.template.metadata.labelswould now be different). Removing the chart label from.spec.template.metadata.labelsand only using it in.metadata.labelsseems to make it work normally.remove unneeded lables form .spec.template.metadata.labels (helm/helm…
jkamenik commentedon Oct 20, 2017
I have this situation in a production deployment. Is there a combination of steps I can perform to change the
.spec.selectoralong with the.spec.template.metadata.labelsto fix this?bacongobbler commentedon Oct 31, 2017
deployment spec selectors are no longer mutable as of apps/v1beta2 and this is noted upstream in kubernetes/kubernetes#50719. Short of
helm delete --purge myreleaseand runninghelm installagain on your chart, there is no way to mutate the selector labels.bacongobbler commentedon Oct 31, 2017
closing as a wontfix/working as intended according to upstream.
[filebeat] Remove chart label from spec.template
rcorre commentedon Jun 7, 2018
@bacongobbler should https://github.com/kubernetes/helm/blob/master/docs/chart_best_practices/labels.md#standard-labels be updated to stop recommending a
chart={{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}label? Seems like anyone following the "best practices" will encounter this issue.I had a thought that maybe the chart label would be fine on the pod metadata as long as it is not in the selector, but it seems that is disallowed:
rcorre commentedon Jun 7, 2018
Is
--purgeoverkill? I'm not sure how wiping out your release history would help -- just deleting should remove the deployment and reset helm's internal state.desaintmartin commentedon Aug 24, 2018
What is the official recommendation from Helm for Deployments regarding this issue? Simply removing .spec.selector.matchLabels? Deleting/recreating a Release or part of it during an upgrade is NOT an option in production, and --force would break any RollingUpdate.
jkamenik commentedon Aug 24, 2018
Not sure this is "official" but what I did was describe the deployments that were failing then I hand edited the chart to make the labels static. That way when helm upgrades the charts those items are not seen as changed.
And I learned from this not to put dynamic data in labels.
rcorre commentedon Dec 4, 2018
It has been about 6 months and the best practices still recommend a
chartlabel.I'm seeing a lot of teams shooting themselves in the foot with this. You create a chart, deploy it successfully, everything seems fine. Then later on you try to upgrade and realize your only option is to
delete --purgeand incur downtime.I see some mention of this in https://github.com/helm/charts/issues/3011, but that seems to be some large meta-issue for a repo separate from these docs.
Draiken commentedon Mar 28, 2019
@rcorre I do think you can manually fix the issue. It's not what Helm should force you to do, but it is a workaround.
You can remove the deployment/replicaset (without cascading, keeping the pods alive), then update the pods labels (and anything that depends on them, like services) then redeploy. The new deployment should recognize those same pods as up already. If not, the new deployment should go live and you can manually remove the old pods with no downtime.
I believe a teammate of mine did this successfully, but I'd definitely recommend testing it out first 🙂
Edit: See below for a proven method
desaintmartin commentedon Mar 28, 2019
You can see how the community charts document this, for example Redis: https://github.com/helm/charts/pull/7686/files#diff-b290a06961a11374d72f584e5925762cR53