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;
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
add a comment |
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
add a comment |
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
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
kubernetes
asked Jun 19 '18 at 18:45
PaddyPaddy
1851 silver badge8 bronze badges
1851 silver badge8 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 anotherDeployment
, or by
creating another controller such as aReplicaSet
or a
ReplicationController
. If you do so, the firstDeployment
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.
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, asspec
is anyway defined belowDeployment
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 anotherDeployment
, or by
creating another controller such as aReplicaSet
or a
ReplicationController
. If you do so, the firstDeployment
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.
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, asspec
is anyway defined belowDeployment
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
add a comment |
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 anotherDeployment
, or by
creating another controller such as aReplicaSet
or a
ReplicationController
. If you do so, the firstDeployment
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.
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, asspec
is anyway defined belowDeployment
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
add a comment |
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 anotherDeployment
, or by
creating another controller such as aReplicaSet
or a
ReplicationController
. If you do so, the firstDeployment
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.
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 anotherDeployment
, or by
creating another controller such as aReplicaSet
or a
ReplicationController
. If you do so, the firstDeployment
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.
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, asspec
is anyway defined belowDeployment
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
add a comment |
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, asspec
is anyway defined belowDeployment
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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