<p>In Kubernetes, ReplicaController uses label selectors to specify which pod(s) it will operate on.</p>

<p>Now, my question is, if multiple ReplicaControllers have overlapping label selectors, what will be the behavior of the Kubernetes cluster? Or is it considered some kind of error and should be avoided?</p>

<p>For example, I have two ReplicationControllers described as below.</p>

<p>rc1.yaml:</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: frontend
spec:
  replicas: 3
  selector:
    app: frontend
    team: payment
</code></pre>

<p>rc2.yaml:</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: backend
spec:
  replicas: 2
  selector:
    app: backend
    team: payment
</code></pre>

<p>You can see that they both have the label selector <code>team=payment</code>, but one specifies a replica count of 3 while another of 2.</p>

<p>Any explanations or references will be appreciated. Thanks.</p>

<p>The <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller/#pod-selector" rel="nofollow noreferrer">Kubernetes docs</a> state the following about overlapping selectors (either from other pods, replication controllers or jobs):</p>

<blockquote>
  <p>Also you should not normally create any pods whose labels match this selector, either directly, with another ReplicationController, or with another controller such as Job. If you do so, the ReplicationController thinks that it created the other pods. Kubernetes does not stop you from doing this.
  If you do end up with multiple controllers that have overlapping selectors, you will have to manage the deletion yourself</p>
</blockquote>

<p>In the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#selector" rel="nofollow noreferrer">docs about Deployments</a> there is another statement that confirms the above:</p>

<blockquote>
  <p>If you have multiple controllers that have overlapping selectors, the controllers will fight with each other and won’t behave correctly.</p>
</blockquote>

<p>So, in summary, you should try to avoid overlapping selectors for replication controllers, replica sets (the next-generation replication controller which I would advise you to use instead of replication controllers) and deployments because it might probably lead to severe problems as confirmed by this <a href="https://github.com/kubernetes/kubernetes/issues/24152" rel="nofollow noreferrer">issue</a>. </p>
