<p>Assuming we have a <code>ReplicaSet</code> definition file as follows:</p>

<pre><code>apiVersion: apps/v1
kind: ReplicaSet
metadata: 
  name: my-deployment
  labels:
    tier: front-end
spec:
  template:
    metadata: 
      name: my-pod
      labels: 
        tier: front-end
    spec:
      containers:
        - name: my-container-1
          image: redis:latest
  replicas: 3
  selector:
    matchLabels:
      tier: front-end-2
</code></pre>

<p>How does <code>kubernetes</code> handle the fact that it should have <strong>3</strong> replicas of two different pods in terms of matched labels (i.e. <code>tier:front-end</code> and <code>tier:front-end-2</code>) ?</p>

<p>Should it make sure that e.g. the sum of these two differently labeled pods equals <strong>3</strong> ?</p>

pkaramol
<p>You would get an error that selector doesnt match pod label. here is the correct config</p>

<pre><code>apiVersion: apps/v1
kind: ReplicaSet
metadata: 
  name: my-deployment
  labels:
    tier: front-end
spec:
  template:
    metadata: 
      name: my-pod
      labels: 
        tier: front-end
    spec:
      containers:
        - name: my-container-1
          image: redis:latest
  replicas: 3
  selector:
    matchLabels:
      tier: front-end
</code></pre>

<p>the pod label in pod spec should match with the selector. The number of replicas is 3. The replicaSet controller ensure that three pods are running at any point of time in the cluster. it uses the selector and the label from pod spec to identify the actual pods running and is matched against the desired count</p>
