title: Kubernetes PodAffinity not able to deploy pods
body: <p>So I have <a href="https://stackoverflow.com/questions/65313780/kubernetes-how-to-config-a-group-of-pods-to-be-deployed-on-the-same-node">this problem</a>, and try to implement <code>podAffinity</code> to solve it.</p>
  <p>I have 3 nodes and want to deploy 2 pods on the same node. In the <code>Deployment</code> YAML files I have <code>service:git</code> under <code>metadata.labels</code>, and the following is the affinity setting:</p>
  <pre><code>  affinity:
      podAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: service
              operator: In
              values:
              - git
          topologyKey: kubernetes.io/hostname
  </code></pre>
  <p>But the pods failed to deploy, I got the following error:</p>
  <pre><code>0/3 nodes are available: 3 node(s) didn't match pod affinity rules, 3 node(s) didn't match pod affinity/anti-affinity.
  </code></pre>
  <p>Are there any problems with my configuration?</p>
  <p>If not, I guess maybe it is because when the first pod is deployed, the system will try to find a node that contains a pod with the label <code>service: git</code> and fail (because it is the first one), and another pod also fail because of the same reason. Is this correct?</p>
  <p>But then how to solve the problem (without resorting to workarounds)?</p>