<p>I have a kubernetes pod and 4 nodes in my cluster. I would like to schedule that pod to <code>node-2</code> first if it's available and then <code>node-4</code>, <code>node-3</code> and last priority to <code>node-1</code>. Assuming that <code>node-x</code> is the built in <code>kubernetes.io/hostname</code> value, is there any way to possibly define a priority for these 4 nodes inside a <code>nodeAffinity</code>?</p>
<p>This is what I've tried:</p>
<pre><code>    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - node-2
            - node-4
            - node-3
            - node-1
</code></pre>
<p>However, the pod seems to always go to node-1.</p>

Aayush Pathak
<p>This seems to be working:</p>
<pre><code>nodeAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchExpressions:
      - key: node-type
        operator: In
        values:
        # a common label applied to all nodes
        - node-label
  preferredDuringSchedulingIgnoredDuringExecution:
  - weight: 100
    preference:
      matchExpressions:
      - key: kubernetes.io/hostname
        operator: In
        values:
        - node-2
  - weight: 50
    preference:
      matchExpressions:
      - key: kubernetes.io/hostname
        operator: In
        values:
        - node-4
  - weight: 20
    preference:
      matchExpressions:
      - key: kubernetes.io/hostname
        operator: In
        values:
        - node-3
.
.
and so on
</code></pre>
