kubernetes : create a Block storage persistent volume kubernetes : create a Block storage persistent volume kubernetes kubernetes

kubernetes : create a Block storage persistent volume


Please keep in mind that PersistentVolumeClaim is "Requesting" something from PersistentVolume.

In short, PV must fulfill some PVC requests. In your YAMLs PV fulfills PVC requests like:

  • Storage: PV has 10Gi, PVC requesting 5Gi. Request fulfiller. (As addition, once PV and PVC bounded, resource will use only requested storage, so in this case 5Gi will be waste. It would be better to use also 5Gi in PV or 10Gi in PVC).
  • AccessMode: Both have ReadWriteOnce.
  • storageClassName: testvolume

Misconfiguration

Your PVC is looking for PV with volumeMode: Block. As your current PV don't have it, it will not be bounded.

Solution

Add volumeMode: Block to your PV configuration and PVC will bound PV.

Tests

As you described your PV you can find information:

VolumeMode:      Filesystem

While $ kubectl describe pvc kubepvc have:

VolumeMode:    Block

When you will add VolumeMode: Block to your PV manifest like below it will work.

apiVersion: v1kind: PersistentVolumemetadata:  name: kubepvspec:  capacity:    storage: 10Gi  accessModes:    - ReadWriteOnce  volumeMode: Block  storageClassName: testvolume  hostPath:    path: "/pvdata"

Notes

Please keep in mind that volumeMode is immutable field, so you need to recreate this resource, it cannot be edited.

The PersistentVolume "kubepv" is invalid: volumeMode: Invalid value: "Block": field is immutable

Regarding storageClass, topic is quite wide but in short as storageClassName is the same in PV and PVC it will work (at least on Kubeadm).

$ kubectl get storageclass -ANo resources founduser@kubeadm:~$ kubectl get pv,pvcNAME                      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM             STORAGECLASS   REASON   AGEpersistentvolume/kubepv   10Gi       RWO            Retain           Bound    default/kubepvc   testvolume              38sNAME                            STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGEpersistentvolumeclaim/kubepvc   Bound    kubepv   10Gi       RWO            testvolume     45s

Useful Documentation