What is spec - selector - matchLabels used for while creating a deployment?How to choose the external IP address of a Kubernetes load balancer in Google Kubernetes EngineUsing environment variables in Kubernetes deployment specKubernetes rolling update that usually retains local data?Mismatch between request external IP and forwarding rule k8s service targetWhat is ContainerCreating in Kubernetes?Is there an established deployment process for Kubernetes and AWS for Windows developers?kube-dns fails open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directoryGetting error while auto provisioning of volumes for the mongodb statefulset on kubernetesIs creating firewall rule for nodeport a security concen?error: unable to recognize “deployment.yaml”: no matches for /, Kind=Deployment

How to fix a dry solder pin in BGA package?

Analog is Obtuse!

In F1 classification, what is ON?

Which ticket do I need to travel by both RER and tram in Paris?

Why isn’t the tax system continuous rather than bracketed?

Why are 120V general receptacle circuits limited to 20A?

One folder two different locations on ubuntu 18.04

Most possible movement by the losing side in a zugzwang position

In the context of a differentiator circuit, what is a “current-sensing resistor”?

How to start learning the piano again

Why did this meteor appear cyan?

Averting Real Women Don’t Wear Dresses

Why is a blank required between "[[" and "-e xxx" in ksh?

What is the consensus on handling pagination in 2019 on big result sets?

Did Chinese school textbook maps (c. 1951) "depict China as stretching even into the central Asian republics"?

Do I have to roll to maintain concentration if a target other than me who is affected by my concentration spell takes damage?

Does a centaur PC also count as being mounted?

Should the Torah be covered or uncovered during the Aliyah blessings?

How to determine what is the correct level of detail when modelling?

Can a police officer film me on their personal device in my own home?

Zombie diet, why humans?

What shortcut does ⌦ symbol in Camunda macOS app indicate and how to invoke it?

Symbol for "not absolutely continuous" in Latex

Which centaur is more 'official'?



What is spec - selector - matchLabels used for while creating a deployment?


How to choose the external IP address of a Kubernetes load balancer in Google Kubernetes EngineUsing environment variables in Kubernetes deployment specKubernetes rolling update that usually retains local data?Mismatch between request external IP and forwarding rule k8s service targetWhat is ContainerCreating in Kubernetes?Is there an established deployment process for Kubernetes and AWS for Windows developers?kube-dns fails open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directoryGetting error while auto provisioning of volumes for the mongodb statefulset on kubernetesIs creating firewall rule for nodeport a security concen?error: unable to recognize “deployment.yaml”: no matches for /, Kind=Deployment






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








13















From Kubernetes documentation




The selector field defines how the Deployment finds which Pods to
manage.




But, when creating deployment, I already specify the pod template as part of the deployment. So, why will I need the selectors as well?



Is it supposed to be used like services, where pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?










share|improve this question




























    13















    From Kubernetes documentation




    The selector field defines how the Deployment finds which Pods to
    manage.




    But, when creating deployment, I already specify the pod template as part of the deployment. So, why will I need the selectors as well?



    Is it supposed to be used like services, where pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?










    share|improve this question
























      13












      13








      13


      3






      From Kubernetes documentation




      The selector field defines how the Deployment finds which Pods to
      manage.




      But, when creating deployment, I already specify the pod template as part of the deployment. So, why will I need the selectors as well?



      Is it supposed to be used like services, where pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?










      share|improve this question














      From Kubernetes documentation




      The selector field defines how the Deployment finds which Pods to
      manage.




      But, when creating deployment, I already specify the pod template as part of the deployment. So, why will I need the selectors as well?



      Is it supposed to be used like services, where pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?







      kubernetes






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 19 '18 at 18:45









      PaddyPaddy

      1851 silver badge8 bronze badges




      1851 silver badge8 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          5














          Answer for this question we can find in section Deployments from kubernetes.io



          So, why will I need the selectors as well?



          Quotes below from documentation for k8s v 1.14




          .spec.selector is an required field that specifies a label selector
          for the Pods targeted by this deployment.



          .spec.selector must match .spec.template.metadata.labels, or it
          will be rejected by the API.



          In API version apps/v1, .spec.selector and .metadata.labels do not
          default to .spec.template.metadata.labels if not set. So they must be
          set explicitly
          . Also note that .spec.selector is immutable after
          creation of the Deployment in apps/v1.



          A Deployment may terminate Pods whose labels match the selector if
          their template is different from .spec.template or if the total number
          of such Pods exceeds .spec.replicas. It brings up new Pods with
          .spec.template if the number of Pods is less than the desired number.




          Pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?



          Simply speaking, No




          Note: You should not create other pods whose labels match this
          selector, either directly, by creating another Deployment, or by
          creating another controller such as a ReplicaSet or a
          ReplicationController. If you do so, the first Deployment thinks
          that it created these other pods. Kubernetes does not stop you from
          doing this. If you have multiple controllers that have overlapping
          selectors, the controllers will fight with each other and won’t behave
          correctly.







          share|improve this answer




















          • 4





            So what is it used for? It seems like you should always make the selector match the labels of the spec… Is there some case where it is useful not to do so?

            – Victor Noël
            Aug 28 '18 at 10:11






          • 3





            Doesn't really answer the question Why? - Why matchLabels exist and must match .spec.template.metadata.labels? What's the point of it, as spec is anyway defined below Deployment so it's clear what Pods are started for the Deployment.

            – Ivan
            Jan 15 at 20:07







          • 1





            Anyone who bumps into this discussion should check the latest documentation. For example, currently, .spec.selector is not an optional field. It is a required field. kubernetes.io/docs/concepts/workloads/controllers/deployment

            – SoftwareTheory
            Jun 10 at 11:34












          • Thanks a lot for your comment. I think that in new documentation authors have corrected optional to required, because in old docs this field was told as optional but on next line authors added that this field must be set explicitly:) So effectively this field also was required

            – alexander.polomodov
            Jun 10 at 12:06













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "2"
          ;
          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%2fserverfault.com%2fquestions%2f917355%2fwhat-is-spec-selector-matchlabels-used-for-while-creating-a-deployment%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









          5














          Answer for this question we can find in section Deployments from kubernetes.io



          So, why will I need the selectors as well?



          Quotes below from documentation for k8s v 1.14




          .spec.selector is an required field that specifies a label selector
          for the Pods targeted by this deployment.



          .spec.selector must match .spec.template.metadata.labels, or it
          will be rejected by the API.



          In API version apps/v1, .spec.selector and .metadata.labels do not
          default to .spec.template.metadata.labels if not set. So they must be
          set explicitly
          . Also note that .spec.selector is immutable after
          creation of the Deployment in apps/v1.



          A Deployment may terminate Pods whose labels match the selector if
          their template is different from .spec.template or if the total number
          of such Pods exceeds .spec.replicas. It brings up new Pods with
          .spec.template if the number of Pods is less than the desired number.




          Pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?



          Simply speaking, No




          Note: You should not create other pods whose labels match this
          selector, either directly, by creating another Deployment, or by
          creating another controller such as a ReplicaSet or a
          ReplicationController. If you do so, the first Deployment thinks
          that it created these other pods. Kubernetes does not stop you from
          doing this. If you have multiple controllers that have overlapping
          selectors, the controllers will fight with each other and won’t behave
          correctly.







          share|improve this answer




















          • 4





            So what is it used for? It seems like you should always make the selector match the labels of the spec… Is there some case where it is useful not to do so?

            – Victor Noël
            Aug 28 '18 at 10:11






          • 3





            Doesn't really answer the question Why? - Why matchLabels exist and must match .spec.template.metadata.labels? What's the point of it, as spec is anyway defined below Deployment so it's clear what Pods are started for the Deployment.

            – Ivan
            Jan 15 at 20:07







          • 1





            Anyone who bumps into this discussion should check the latest documentation. For example, currently, .spec.selector is not an optional field. It is a required field. kubernetes.io/docs/concepts/workloads/controllers/deployment

            – SoftwareTheory
            Jun 10 at 11:34












          • Thanks a lot for your comment. I think that in new documentation authors have corrected optional to required, because in old docs this field was told as optional but on next line authors added that this field must be set explicitly:) So effectively this field also was required

            – alexander.polomodov
            Jun 10 at 12:06















          5














          Answer for this question we can find in section Deployments from kubernetes.io



          So, why will I need the selectors as well?



          Quotes below from documentation for k8s v 1.14




          .spec.selector is an required field that specifies a label selector
          for the Pods targeted by this deployment.



          .spec.selector must match .spec.template.metadata.labels, or it
          will be rejected by the API.



          In API version apps/v1, .spec.selector and .metadata.labels do not
          default to .spec.template.metadata.labels if not set. So they must be
          set explicitly
          . Also note that .spec.selector is immutable after
          creation of the Deployment in apps/v1.



          A Deployment may terminate Pods whose labels match the selector if
          their template is different from .spec.template or if the total number
          of such Pods exceeds .spec.replicas. It brings up new Pods with
          .spec.template if the number of Pods is less than the desired number.




          Pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?



          Simply speaking, No




          Note: You should not create other pods whose labels match this
          selector, either directly, by creating another Deployment, or by
          creating another controller such as a ReplicaSet or a
          ReplicationController. If you do so, the first Deployment thinks
          that it created these other pods. Kubernetes does not stop you from
          doing this. If you have multiple controllers that have overlapping
          selectors, the controllers will fight with each other and won’t behave
          correctly.







          share|improve this answer




















          • 4





            So what is it used for? It seems like you should always make the selector match the labels of the spec… Is there some case where it is useful not to do so?

            – Victor Noël
            Aug 28 '18 at 10:11






          • 3





            Doesn't really answer the question Why? - Why matchLabels exist and must match .spec.template.metadata.labels? What's the point of it, as spec is anyway defined below Deployment so it's clear what Pods are started for the Deployment.

            – Ivan
            Jan 15 at 20:07







          • 1





            Anyone who bumps into this discussion should check the latest documentation. For example, currently, .spec.selector is not an optional field. It is a required field. kubernetes.io/docs/concepts/workloads/controllers/deployment

            – SoftwareTheory
            Jun 10 at 11:34












          • Thanks a lot for your comment. I think that in new documentation authors have corrected optional to required, because in old docs this field was told as optional but on next line authors added that this field must be set explicitly:) So effectively this field also was required

            – alexander.polomodov
            Jun 10 at 12:06













          5












          5








          5







          Answer for this question we can find in section Deployments from kubernetes.io



          So, why will I need the selectors as well?



          Quotes below from documentation for k8s v 1.14




          .spec.selector is an required field that specifies a label selector
          for the Pods targeted by this deployment.



          .spec.selector must match .spec.template.metadata.labels, or it
          will be rejected by the API.



          In API version apps/v1, .spec.selector and .metadata.labels do not
          default to .spec.template.metadata.labels if not set. So they must be
          set explicitly
          . Also note that .spec.selector is immutable after
          creation of the Deployment in apps/v1.



          A Deployment may terminate Pods whose labels match the selector if
          their template is different from .spec.template or if the total number
          of such Pods exceeds .spec.replicas. It brings up new Pods with
          .spec.template if the number of Pods is less than the desired number.




          Pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?



          Simply speaking, No




          Note: You should not create other pods whose labels match this
          selector, either directly, by creating another Deployment, or by
          creating another controller such as a ReplicaSet or a
          ReplicationController. If you do so, the first Deployment thinks
          that it created these other pods. Kubernetes does not stop you from
          doing this. If you have multiple controllers that have overlapping
          selectors, the controllers will fight with each other and won’t behave
          correctly.







          share|improve this answer















          Answer for this question we can find in section Deployments from kubernetes.io



          So, why will I need the selectors as well?



          Quotes below from documentation for k8s v 1.14




          .spec.selector is an required field that specifies a label selector
          for the Pods targeted by this deployment.



          .spec.selector must match .spec.template.metadata.labels, or it
          will be rejected by the API.



          In API version apps/v1, .spec.selector and .metadata.labels do not
          default to .spec.template.metadata.labels if not set. So they must be
          set explicitly
          . Also note that .spec.selector is immutable after
          creation of the Deployment in apps/v1.



          A Deployment may terminate Pods whose labels match the selector if
          their template is different from .spec.template or if the total number
          of such Pods exceeds .spec.replicas. It brings up new Pods with
          .spec.template if the number of Pods is less than the desired number.




          Pods are already being started separately, but later brought under the umbrella of Deployment to be managed together?



          Simply speaking, No




          Note: You should not create other pods whose labels match this
          selector, either directly, by creating another Deployment, or by
          creating another controller such as a ReplicaSet or a
          ReplicationController. If you do so, the first Deployment thinks
          that it created these other pods. Kubernetes does not stop you from
          doing this. If you have multiple controllers that have overlapping
          selectors, the controllers will fight with each other and won’t behave
          correctly.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 10 at 11:59

























          answered Jun 19 '18 at 19:17









          alexander.polomodovalexander.polomodov

          1,0263 gold badges7 silver badges12 bronze badges




          1,0263 gold badges7 silver badges12 bronze badges







          • 4





            So what is it used for? It seems like you should always make the selector match the labels of the spec… Is there some case where it is useful not to do so?

            – Victor Noël
            Aug 28 '18 at 10:11






          • 3





            Doesn't really answer the question Why? - Why matchLabels exist and must match .spec.template.metadata.labels? What's the point of it, as spec is anyway defined below Deployment so it's clear what Pods are started for the Deployment.

            – Ivan
            Jan 15 at 20:07







          • 1





            Anyone who bumps into this discussion should check the latest documentation. For example, currently, .spec.selector is not an optional field. It is a required field. kubernetes.io/docs/concepts/workloads/controllers/deployment

            – SoftwareTheory
            Jun 10 at 11:34












          • Thanks a lot for your comment. I think that in new documentation authors have corrected optional to required, because in old docs this field was told as optional but on next line authors added that this field must be set explicitly:) So effectively this field also was required

            – alexander.polomodov
            Jun 10 at 12:06












          • 4





            So what is it used for? It seems like you should always make the selector match the labels of the spec… Is there some case where it is useful not to do so?

            – Victor Noël
            Aug 28 '18 at 10:11






          • 3





            Doesn't really answer the question Why? - Why matchLabels exist and must match .spec.template.metadata.labels? What's the point of it, as spec is anyway defined below Deployment so it's clear what Pods are started for the Deployment.

            – Ivan
            Jan 15 at 20:07







          • 1





            Anyone who bumps into this discussion should check the latest documentation. For example, currently, .spec.selector is not an optional field. It is a required field. kubernetes.io/docs/concepts/workloads/controllers/deployment

            – SoftwareTheory
            Jun 10 at 11:34












          • Thanks a lot for your comment. I think that in new documentation authors have corrected optional to required, because in old docs this field was told as optional but on next line authors added that this field must be set explicitly:) So effectively this field also was required

            – alexander.polomodov
            Jun 10 at 12:06







          4




          4





          So what is it used for? It seems like you should always make the selector match the labels of the spec… Is there some case where it is useful not to do so?

          – Victor Noël
          Aug 28 '18 at 10:11





          So what is it used for? It seems like you should always make the selector match the labels of the spec… Is there some case where it is useful not to do so?

          – Victor Noël
          Aug 28 '18 at 10:11




          3




          3





          Doesn't really answer the question Why? - Why matchLabels exist and must match .spec.template.metadata.labels? What's the point of it, as spec is anyway defined below Deployment so it's clear what Pods are started for the Deployment.

          – Ivan
          Jan 15 at 20:07






          Doesn't really answer the question Why? - Why matchLabels exist and must match .spec.template.metadata.labels? What's the point of it, as spec is anyway defined below Deployment so it's clear what Pods are started for the Deployment.

          – Ivan
          Jan 15 at 20:07





          1




          1





          Anyone who bumps into this discussion should check the latest documentation. For example, currently, .spec.selector is not an optional field. It is a required field. kubernetes.io/docs/concepts/workloads/controllers/deployment

          – SoftwareTheory
          Jun 10 at 11:34






          Anyone who bumps into this discussion should check the latest documentation. For example, currently, .spec.selector is not an optional field. It is a required field. kubernetes.io/docs/concepts/workloads/controllers/deployment

          – SoftwareTheory
          Jun 10 at 11:34














          Thanks a lot for your comment. I think that in new documentation authors have corrected optional to required, because in old docs this field was told as optional but on next line authors added that this field must be set explicitly:) So effectively this field also was required

          – alexander.polomodov
          Jun 10 at 12:06





          Thanks a lot for your comment. I think that in new documentation authors have corrected optional to required, because in old docs this field was told as optional but on next line authors added that this field must be set explicitly:) So effectively this field also was required

          – alexander.polomodov
          Jun 10 at 12:06

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Server Fault!


          • 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%2fserverfault.com%2fquestions%2f917355%2fwhat-is-spec-selector-matchlabels-used-for-while-creating-a-deployment%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

          Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

          Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

          What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company