2

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.)

larsks
  • 41,276
  • 13
  • 117
  • 170
  • Your concern is not at all correct. They could work with the same label however you must apply to the label selector to identify the set of objects. Please consider [this note](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) or could you confirm if you consider this situation? – Gabriel Robledo Ahumada Sep 14 '22 at 23:18
  • @GabrielRobledoAhumada "not at all correct" reads a little bit rude, as if you are disregarding the question. or do you mean "not fully correct"? – criztovyl Sep 15 '22 at 06:01

0 Answers0