<p>The example code given in the documentation doesn't state which items it can be used on. Can you use node selector on deployments/statefulsets/persistentvolumes? Also when I put the node Selector under</p>

<p>.spec.nodeSelector as such</p>

<pre class="lang-yaml prettyprint-override"><code>spec:
  nodeSelector:
    workload: node-selector-app
</code></pre>

<p>I get a validation error when attempting a dry run of the deployment/statefulset/persistentvolume. So can nodeSelector only be used on Pods?</p>

mjwrazor
<p><code>nodeSelector</code> can not be used in persistentVolumes.<code>nodeSelector</code> should be in the spec section of pod template. Example of deployment using <code>nodeSelector</code></p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
      nodeSelector:
        workload: node-selector-app
</code></pre>

<p>With <code>persistentVolume</code> you can use <code>nodeAffinity</code></p>

<pre><code>kubectl explain persistentVolume.spec.nodeAffinity
KIND:     PersistentVolume
VERSION:  v1

RESOURCE: nodeAffinity &lt;Object&gt;

DESCRIPTION:
     NodeAffinity defines constraints that limit what nodes this volume can be
     accessed from. This field influences the scheduling of pods that use this
     volume.

     VolumeNodeAffinity defines constraints that limit what nodes this volume
     can be accessed from.

FIELDS:
   required &lt;Object&gt;
     Required specifies hard node constraints that must be met.
</code></pre>

<p>An example:</p>

<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-local-pv
spec:
  capacity:
    storage: 500Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /mnt/disks/vol1
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - my-node
</code></pre>
