<p>I have a specific node I know by hostname (as seen in <code>kubectl describe pods</code>). I suspect a hardware incompatibility and would like to exclude that node from my job.</p>
<p>I've tried to use <code>podAntiAffinity</code> without success (my job is still assigned to <code>my.hostname.net</code>). What is the correct way to accomplish this?</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: my-job-name
spec:
  backoffLimit: 0
  template:
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: kubernetes.io/hostname
                operator: NotIn
                values:
                - my.hostname.net
            topologyKey: kubernetes.io/hostname
      containers:
        &lt;&lt;the rest omitted&gt;&gt;
</code></pre>

<p>Ah, I figured it out thanks to @zerkms's comment. Using <code>nodeAffinity</code> with the <code>NotIn</code> operator excludes nodes by hostname as desired:</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: my-job-name
spec:
  template:
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: NotIn
                values:
                - my.hostname.net
                - another.hostname.net
      containers:
        &lt;&lt;omitted&gt;&gt;
</code></pre>
