Error: selector does not match template labels












0














My task is to add a label named "app" to all deployments, daemonsets, and cronjobs so that it's easier to query our apps across the stack in our monitoring tools. This way, we can build dashboards that use a single selector, namely app.



To avoid downtime I've decided to resolve this issue in the following steps:




  1. Add labels to dev, test & stage environments.

  2. Add labels to prod env's.

  3. Deploy (1)

  4. Deploy (2)

  5. Delete old labels & update the services of dev to use the new labels. Then test & deploy. (currently on this step)

  6. Repeat (5) for stage.

  7. Repeat (5) for prod.


When using $ kubectl apply to update the resources I've added the "app" label to/replaced "service" label with "app" labels to, I run into the following error:




Error from server (Invalid): error when applying patch:
{longAssPatchWhichIWon'tIncludeButYaGetThePoint} to: &{0xc421b02f00
0xc420803650 default provisioning
manifests/prod/provisioning-deployment.yaml 0xc 42000c6f8 3942200
false} for: "manifests/prod/provisioning-deployment.yaml":
Deployment.apps "provisioning" is invalid: s
pec.template.metadata.labels: Invalid value:
map[string]string{"app":"provisioning", "component" :"marketplace"}:
selector does not match template labels




I need some insights on why it's throwing this error.










share|improve this question
























  • Can you share yaml for the deployment? One quick reminder, your deployment's spec.selector has to match labels of spec.template.metadata.labels.
    – Emruz Hossain
    Nov 14 '18 at 16:43












  • @EmruzHossain I understand but even after that update I still received the same error. I've included my .yaml file.
    – v1mg1rl
    Nov 14 '18 at 17:20










  • You should insert your code or manifests or something like to your problem description instead of inserting them by link
    – Shudipta Sharma
    Nov 14 '18 at 17:29










  • Correct your indentation in spec.selector.matchLabels, spec.selector.matchLabels.app and spec.selector.matchLabels.component. You have used 4 spaces instead of 2 spaces.
    – Shudipta Sharma
    Nov 14 '18 at 17:37
















0














My task is to add a label named "app" to all deployments, daemonsets, and cronjobs so that it's easier to query our apps across the stack in our monitoring tools. This way, we can build dashboards that use a single selector, namely app.



To avoid downtime I've decided to resolve this issue in the following steps:




  1. Add labels to dev, test & stage environments.

  2. Add labels to prod env's.

  3. Deploy (1)

  4. Deploy (2)

  5. Delete old labels & update the services of dev to use the new labels. Then test & deploy. (currently on this step)

  6. Repeat (5) for stage.

  7. Repeat (5) for prod.


When using $ kubectl apply to update the resources I've added the "app" label to/replaced "service" label with "app" labels to, I run into the following error:




Error from server (Invalid): error when applying patch:
{longAssPatchWhichIWon'tIncludeButYaGetThePoint} to: &{0xc421b02f00
0xc420803650 default provisioning
manifests/prod/provisioning-deployment.yaml 0xc 42000c6f8 3942200
false} for: "manifests/prod/provisioning-deployment.yaml":
Deployment.apps "provisioning" is invalid: s
pec.template.metadata.labels: Invalid value:
map[string]string{"app":"provisioning", "component" :"marketplace"}:
selector does not match template labels




I need some insights on why it's throwing this error.










share|improve this question
























  • Can you share yaml for the deployment? One quick reminder, your deployment's spec.selector has to match labels of spec.template.metadata.labels.
    – Emruz Hossain
    Nov 14 '18 at 16:43












  • @EmruzHossain I understand but even after that update I still received the same error. I've included my .yaml file.
    – v1mg1rl
    Nov 14 '18 at 17:20










  • You should insert your code or manifests or something like to your problem description instead of inserting them by link
    – Shudipta Sharma
    Nov 14 '18 at 17:29










  • Correct your indentation in spec.selector.matchLabels, spec.selector.matchLabels.app and spec.selector.matchLabels.component. You have used 4 spaces instead of 2 spaces.
    – Shudipta Sharma
    Nov 14 '18 at 17:37














0












0








0







My task is to add a label named "app" to all deployments, daemonsets, and cronjobs so that it's easier to query our apps across the stack in our monitoring tools. This way, we can build dashboards that use a single selector, namely app.



To avoid downtime I've decided to resolve this issue in the following steps:




  1. Add labels to dev, test & stage environments.

  2. Add labels to prod env's.

  3. Deploy (1)

  4. Deploy (2)

  5. Delete old labels & update the services of dev to use the new labels. Then test & deploy. (currently on this step)

  6. Repeat (5) for stage.

  7. Repeat (5) for prod.


When using $ kubectl apply to update the resources I've added the "app" label to/replaced "service" label with "app" labels to, I run into the following error:




Error from server (Invalid): error when applying patch:
{longAssPatchWhichIWon'tIncludeButYaGetThePoint} to: &{0xc421b02f00
0xc420803650 default provisioning
manifests/prod/provisioning-deployment.yaml 0xc 42000c6f8 3942200
false} for: "manifests/prod/provisioning-deployment.yaml":
Deployment.apps "provisioning" is invalid: s
pec.template.metadata.labels: Invalid value:
map[string]string{"app":"provisioning", "component" :"marketplace"}:
selector does not match template labels




I need some insights on why it's throwing this error.










share|improve this question















My task is to add a label named "app" to all deployments, daemonsets, and cronjobs so that it's easier to query our apps across the stack in our monitoring tools. This way, we can build dashboards that use a single selector, namely app.



To avoid downtime I've decided to resolve this issue in the following steps:




  1. Add labels to dev, test & stage environments.

  2. Add labels to prod env's.

  3. Deploy (1)

  4. Deploy (2)

  5. Delete old labels & update the services of dev to use the new labels. Then test & deploy. (currently on this step)

  6. Repeat (5) for stage.

  7. Repeat (5) for prod.


When using $ kubectl apply to update the resources I've added the "app" label to/replaced "service" label with "app" labels to, I run into the following error:




Error from server (Invalid): error when applying patch:
{longAssPatchWhichIWon'tIncludeButYaGetThePoint} to: &{0xc421b02f00
0xc420803650 default provisioning
manifests/prod/provisioning-deployment.yaml 0xc 42000c6f8 3942200
false} for: "manifests/prod/provisioning-deployment.yaml":
Deployment.apps "provisioning" is invalid: s
pec.template.metadata.labels: Invalid value:
map[string]string{"app":"provisioning", "component" :"marketplace"}:
selector does not match template labels




I need some insights on why it's throwing this error.







kubernetes yaml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 14:14

























asked Nov 14 '18 at 16:12









v1mg1rl

358




358












  • Can you share yaml for the deployment? One quick reminder, your deployment's spec.selector has to match labels of spec.template.metadata.labels.
    – Emruz Hossain
    Nov 14 '18 at 16:43












  • @EmruzHossain I understand but even after that update I still received the same error. I've included my .yaml file.
    – v1mg1rl
    Nov 14 '18 at 17:20










  • You should insert your code or manifests or something like to your problem description instead of inserting them by link
    – Shudipta Sharma
    Nov 14 '18 at 17:29










  • Correct your indentation in spec.selector.matchLabels, spec.selector.matchLabels.app and spec.selector.matchLabels.component. You have used 4 spaces instead of 2 spaces.
    – Shudipta Sharma
    Nov 14 '18 at 17:37


















  • Can you share yaml for the deployment? One quick reminder, your deployment's spec.selector has to match labels of spec.template.metadata.labels.
    – Emruz Hossain
    Nov 14 '18 at 16:43












  • @EmruzHossain I understand but even after that update I still received the same error. I've included my .yaml file.
    – v1mg1rl
    Nov 14 '18 at 17:20










  • You should insert your code or manifests or something like to your problem description instead of inserting them by link
    – Shudipta Sharma
    Nov 14 '18 at 17:29










  • Correct your indentation in spec.selector.matchLabels, spec.selector.matchLabels.app and spec.selector.matchLabels.component. You have used 4 spaces instead of 2 spaces.
    – Shudipta Sharma
    Nov 14 '18 at 17:37
















Can you share yaml for the deployment? One quick reminder, your deployment's spec.selector has to match labels of spec.template.metadata.labels.
– Emruz Hossain
Nov 14 '18 at 16:43






Can you share yaml for the deployment? One quick reminder, your deployment's spec.selector has to match labels of spec.template.metadata.labels.
– Emruz Hossain
Nov 14 '18 at 16:43














@EmruzHossain I understand but even after that update I still received the same error. I've included my .yaml file.
– v1mg1rl
Nov 14 '18 at 17:20




@EmruzHossain I understand but even after that update I still received the same error. I've included my .yaml file.
– v1mg1rl
Nov 14 '18 at 17:20












You should insert your code or manifests or something like to your problem description instead of inserting them by link
– Shudipta Sharma
Nov 14 '18 at 17:29




You should insert your code or manifests or something like to your problem description instead of inserting them by link
– Shudipta Sharma
Nov 14 '18 at 17:29












Correct your indentation in spec.selector.matchLabels, spec.selector.matchLabels.app and spec.selector.matchLabels.component. You have used 4 spaces instead of 2 spaces.
– Shudipta Sharma
Nov 14 '18 at 17:37




Correct your indentation in spec.selector.matchLabels, spec.selector.matchLabels.app and spec.selector.matchLabels.component. You have used 4 spaces instead of 2 spaces.
– Shudipta Sharma
Nov 14 '18 at 17:37












1 Answer
1






active

oldest

votes


















1














It seems you are in trouble. Check this section: Label selector updates




Note: In API version apps/v1, a Deployment’s label selector is immutable after it gets created.




So, this line say you can not update selector once deployment is created. Selector can not be changed for any API version except apps/v1beta1 and extension/v1beta1. Ref: TestDeploymentSelectorImmutability.



One possible workaround might be to keep the old labels and adding new labels along with old ones. This way, you don't have to update selector. Deployment will select pods using old labels but your dashboard can select using new labels. This might not meet your requirement but I don't see any better way.






share|improve this answer





















  • The API version I have for that file is extension/v1beta1. So I should be able to change/update the selector right?
    – v1mg1rl
    Nov 14 '18 at 20:15










  • Theoretically, yes. I haven't tried. You have read Label selector updates section I have linked in my answer, right? There are some problem in changing selector. Old ReplicaSet will be orphaned. Also, be sure that your deployment is extension/v1beta1 api version. kubectl will always return extension api group even if your deployment is apps/v1. Ref: github.com/kubernetes/kubernetes/issues/…
    – Emruz Hossain
    Nov 15 '18 at 3:28













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304461%2ferror-selector-does-not-match-template-labels%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














It seems you are in trouble. Check this section: Label selector updates




Note: In API version apps/v1, a Deployment’s label selector is immutable after it gets created.




So, this line say you can not update selector once deployment is created. Selector can not be changed for any API version except apps/v1beta1 and extension/v1beta1. Ref: TestDeploymentSelectorImmutability.



One possible workaround might be to keep the old labels and adding new labels along with old ones. This way, you don't have to update selector. Deployment will select pods using old labels but your dashboard can select using new labels. This might not meet your requirement but I don't see any better way.






share|improve this answer





















  • The API version I have for that file is extension/v1beta1. So I should be able to change/update the selector right?
    – v1mg1rl
    Nov 14 '18 at 20:15










  • Theoretically, yes. I haven't tried. You have read Label selector updates section I have linked in my answer, right? There are some problem in changing selector. Old ReplicaSet will be orphaned. Also, be sure that your deployment is extension/v1beta1 api version. kubectl will always return extension api group even if your deployment is apps/v1. Ref: github.com/kubernetes/kubernetes/issues/…
    – Emruz Hossain
    Nov 15 '18 at 3:28


















1














It seems you are in trouble. Check this section: Label selector updates




Note: In API version apps/v1, a Deployment’s label selector is immutable after it gets created.




So, this line say you can not update selector once deployment is created. Selector can not be changed for any API version except apps/v1beta1 and extension/v1beta1. Ref: TestDeploymentSelectorImmutability.



One possible workaround might be to keep the old labels and adding new labels along with old ones. This way, you don't have to update selector. Deployment will select pods using old labels but your dashboard can select using new labels. This might not meet your requirement but I don't see any better way.






share|improve this answer





















  • The API version I have for that file is extension/v1beta1. So I should be able to change/update the selector right?
    – v1mg1rl
    Nov 14 '18 at 20:15










  • Theoretically, yes. I haven't tried. You have read Label selector updates section I have linked in my answer, right? There are some problem in changing selector. Old ReplicaSet will be orphaned. Also, be sure that your deployment is extension/v1beta1 api version. kubectl will always return extension api group even if your deployment is apps/v1. Ref: github.com/kubernetes/kubernetes/issues/…
    – Emruz Hossain
    Nov 15 '18 at 3:28
















1












1








1






It seems you are in trouble. Check this section: Label selector updates




Note: In API version apps/v1, a Deployment’s label selector is immutable after it gets created.




So, this line say you can not update selector once deployment is created. Selector can not be changed for any API version except apps/v1beta1 and extension/v1beta1. Ref: TestDeploymentSelectorImmutability.



One possible workaround might be to keep the old labels and adding new labels along with old ones. This way, you don't have to update selector. Deployment will select pods using old labels but your dashboard can select using new labels. This might not meet your requirement but I don't see any better way.






share|improve this answer












It seems you are in trouble. Check this section: Label selector updates




Note: In API version apps/v1, a Deployment’s label selector is immutable after it gets created.




So, this line say you can not update selector once deployment is created. Selector can not be changed for any API version except apps/v1beta1 and extension/v1beta1. Ref: TestDeploymentSelectorImmutability.



One possible workaround might be to keep the old labels and adding new labels along with old ones. This way, you don't have to update selector. Deployment will select pods using old labels but your dashboard can select using new labels. This might not meet your requirement but I don't see any better way.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 18:27









Emruz Hossain

1,084210




1,084210












  • The API version I have for that file is extension/v1beta1. So I should be able to change/update the selector right?
    – v1mg1rl
    Nov 14 '18 at 20:15










  • Theoretically, yes. I haven't tried. You have read Label selector updates section I have linked in my answer, right? There are some problem in changing selector. Old ReplicaSet will be orphaned. Also, be sure that your deployment is extension/v1beta1 api version. kubectl will always return extension api group even if your deployment is apps/v1. Ref: github.com/kubernetes/kubernetes/issues/…
    – Emruz Hossain
    Nov 15 '18 at 3:28




















  • The API version I have for that file is extension/v1beta1. So I should be able to change/update the selector right?
    – v1mg1rl
    Nov 14 '18 at 20:15










  • Theoretically, yes. I haven't tried. You have read Label selector updates section I have linked in my answer, right? There are some problem in changing selector. Old ReplicaSet will be orphaned. Also, be sure that your deployment is extension/v1beta1 api version. kubectl will always return extension api group even if your deployment is apps/v1. Ref: github.com/kubernetes/kubernetes/issues/…
    – Emruz Hossain
    Nov 15 '18 at 3:28


















The API version I have for that file is extension/v1beta1. So I should be able to change/update the selector right?
– v1mg1rl
Nov 14 '18 at 20:15




The API version I have for that file is extension/v1beta1. So I should be able to change/update the selector right?
– v1mg1rl
Nov 14 '18 at 20:15












Theoretically, yes. I haven't tried. You have read Label selector updates section I have linked in my answer, right? There are some problem in changing selector. Old ReplicaSet will be orphaned. Also, be sure that your deployment is extension/v1beta1 api version. kubectl will always return extension api group even if your deployment is apps/v1. Ref: github.com/kubernetes/kubernetes/issues/…
– Emruz Hossain
Nov 15 '18 at 3:28






Theoretically, yes. I haven't tried. You have read Label selector updates section I have linked in my answer, right? There are some problem in changing selector. Old ReplicaSet will be orphaned. Also, be sure that your deployment is extension/v1beta1 api version. kubectl will always return extension api group even if your deployment is apps/v1. Ref: github.com/kubernetes/kubernetes/issues/…
– Emruz Hossain
Nov 15 '18 at 3:28




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304461%2ferror-selector-does-not-match-template-labels%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)