<p>Is it a good practice (feasible) to <strong>combine both nodeAfinity and podAffinity rules</strong> when assigning Pods to Nodes on kubernetes.</p>

<p>Example : </p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: node-and-pod-affinity-combined
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/e2e-az-name
            operator: In
            values:
            - e2e-az1
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: node-label-key
            operator: In
            values:
            - some-node-label-value
</code></pre>

DT.
<p>Sure you can combine them. Actually this enforces a sort of affinity on scheduling of pods you have selected using <code>podAffinity</code>. Even if those pods do not have any nodeAffinity or podAffinity themselves, scheduler will try to schedule them to nodes on which your <code>node-and-pod-affinity-combined</code> pods are running. </p>

<p>More common use case would be using <code>nodeAffinity</code> and <code>podAntiAffinity</code> together to spread the pods on set of nodes.</p>
