<p>What I would like is to use podAntiAffinity to limit the number of pods I run on a host of the same version of code.</p>
<p>Specifically, I would like to run 1 pod of version A, and 1 pod of version B.  This is to allow to canary deploys without spinning up a large number of new nodes.</p>
<p>I have tried setting my podAntiAffinity</p>
<pre><code>        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                - matchExpressions:
                  - key: &quot;k8s.git/commit-sha&quot;
                    operator: In
                    values:
                    - valueFrom:
                        fieldRef:
                          fieldPath: &quot;metadata.labels['k8s.git/commit-sha']&quot;
                topologyKey: kubernetes.io/hostname
              weight: 100
</code></pre>
<p>But looking at the source code for k8s, it expected a <code>string</code> object instead of a <code>map</code> object.</p>
<p>Is there another way to accomplish this?  Has anyone implemented something similar?  I'm running Kubernetes 1.18.</p>

Mark Robinson
<p>I had this thought before and I resolved it using the method describe here <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity" rel="nofollow noreferrer">Inter-pod affinity</a>. In short, the method deploy to nodes that already run pod that match the intend label - which in your case the commit-sha.</p>
