Node didn't find available persistent volumes to bind

12/28/2018

I am getting error of

1 node(s) didn't find available persistent volumes to bind.

upon creating my pod to attach to Persistent Storage.

I have setup below.

PersistentVolume and StorageClass created and attached successfully. Once I create PersistentVolumeClaim, it waits in "pending" state, which is expected (I believe) because it waits a pod to connect due to "WaitForFirstConsumer" setting of StorageClass.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-local-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /home/aozdemir/k8s
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - my-node
---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: example-local-claim
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: local-storage
  resources:
    requests:
      storage: 2Gi
---
kind: Pod
apiVersion: v1
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
       claimName: example-local-claim
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-storage

My problem is that, after I create the Pod, it gives following warning:

0/1 nodes are available: 1 node(s) didn't find available persistent volumes to bind.

Here is screenshot:

enter image description here

Am I missing something here?

-- Teoman shipahi
kubernetes

1 Answer

12/28/2018

It was my bad. Due to following blog post: https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/

Note that there’s a new nodeAffinity field in the PersistentVolume object: this is how the Kubernetes scheduler understands that this PersistentVolume is tied to a specific node. nodeAffinity is a required field for local PersistentVolumes.

and my value was incorrect. I changed it to my node name, and re-deployed, it worked.

-- Teoman shipahi
Source: StackOverflow