<p>I am getting the following error on deployment:</p>
<pre><code>  Warning  FailedScheduling  0s (x2 over 0s)  default-scheduler  0/1 nodes are available: 1 node(s) had volume node affinity conflict.
</code></pre>
<p>Here are the yaml files.</p>
<pre><code>dev-storage-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

dev-volume-pv-claim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dev-volume-pv-claim
spec:
  # storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

dev-volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: dev-volume
  labels:
    type: local
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  # storageClassName: local-storage
  local:
    path: /home/code
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
              - dev-volume

docs.yaml
apiVersion: v1
kind: Pod
metadata:
  name: docs
spec:
  volumes:
    - name: dev-volume-storage
      persistentVolumeClaim:
        claimName: dev-volume-pv-claim
  containers:
    - image: our/docs
      name: docs
      resources: {}
      volumeMounts:
        - mountPath: &quot;/app&quot;
          name: dev-volume-storage
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
</code></pre>
<p><strong>UPDATE:</strong>
The following seems to work. I had to create a label clustername (or whatever you choose) and use that in the affinity filter</p>
<pre><code>dev-storage-class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

dev-volume-pv-claim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dev-volume-pv-claim
spec:
  # storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

dev-volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: dev-volume
  labels:
    clustername: local
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  # storageClassName: local-storage
  local:
    path: /home/myproj
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
          - key: clustername
            operator: In
            values:
              - local

docs.yaml
apiVersion: v1
kind: Pod
metadata:
  name: docs
spec:
  volumes:
    - name: dev-volume-storage
      persistentVolumeClaim:
        claimName: dev-volume-pv-claim
  containers:
    - image: our/docs:local
      name: docs
      resources: {}
      volumeMounts:
        - mountPath: &quot;/app/code&quot;
          name: dev-volume-storage
      ports:
        - containerPort: 8080
  dnsPolicy: ClusterFirst
  restartPolicy: Always
  nodeSelector:
    clustername: local
status: {}
</code></pre>

mathtick
<p>Your PV define a nodeAffinity:</p>
<pre><code>nodeAffinity:
  required:
    nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
            - dev-volume
</code></pre>
<p>This is basically asking for the PV to get created in the node of the Kubernetes cluster with hostname equal to dev-volume. And since the Pod uses that PV, the Pod will be scheduled only on nodes selected by the affinity specified in the PV. (
<a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#node-affinity" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/#node-affinity</a>)</p>
<p>You can see labels of nodes with the command:</p>
<pre><code>kubectl get nodes --show-labels
</code></pre>
<p>And you can add (and also remove) labels from nodes with:</p>
<pre><code>kubectl label nodes &lt;your-node-name&gt; disktype=ssd
</code></pre>
<p>With this said, if I understood correctly, you want to schedule a Pod which mounts a local filesystem path on one of your nodes. If you have <strong>only one node</strong>, you could simply remove the nodeAffinity part of the PV definition.</p>
<p>If you have more than one node and you want the Pod to be scheduled on a specific node of the cluster, so that the local filesystem used is on a certain node, you can edit the nodeAffinity of the PV to match the hostname of the specific node you want it to get scheduled on.</p>
<p>You can also give the Pod a nodeSelector, with something like:</p>
<pre><code>nodeSelector:
  disktype: ssd
</code></pre>
<p>This node selector will match nodes with label disktype=ssd</p>
<p>For more info on this, you could check Kubernetes documentation:
<a href="https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/</a></p>
