Responda a esta pergunta que podemos encontrar na seção Implantações em kubernetes.io
Então, por que eu preciso dos seletores também?
.spec.selector
is an optional 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.
Os pods já estão sendo iniciados separadamente, mas depois trazidos para o Deployment para serem gerenciados juntos?
Falando simplesmente, Não
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 aReplicaSet
or aReplicationController
. 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.