The documentation for .spec.selector
says:
The
.spec.selector
field defines how the Deployment finds which Pods to manage. In this case, you select a label that is defined in the Pod template (app: nginx
). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.
But what happens if multiple Deployments create pods that share the same labels? That is, if I have:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: app
name: app1
spec:
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
...
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: app
name: app2
spec:
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
...
What is the practical impact of that? Given the above configuration,
things like kubectl scale --replicas=<n> app1
appear to work
correctly, so there's no confusion about which pods are being managed
by which deployments.
The only practical impact I've noticed is that attempting to target
pods by deployment name (as in kubectl logs deploy/app1
) will pick
the wrong pod given the above configuration.
Is that the only problem? I ask because I've noticed we have this situation in a couple of places and I am trying to judge the severity of the problem.
(I realize that having identically labelled pods may cause other problems -- e.g., a Service
may actually direct traffic to the incorrect pod -- but I'm interested in ways in which this will cause problems specifically with deployments and their management of pods.)