<p>I am new to kubernetes volumes management.
I need to use a block pvc with th following pod:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: buggypod
spec:
  containers:
  - name: container
    image: ubuntu
    command: [ &quot;bash&quot; ]
    volumeDevices:
    - devicePath: /tmp
      name: podpvc
################
  restartPolicy: Never
  terminationGracePeriodSeconds: 0
  volumes:
  - name: podpvc
    persistentVolumeClaim:
      claimName: kubepvc
</code></pre>
<p>I create the following pvc</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kubepvc
spec:
  storageClassName: testvolume
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  volumeMode: Block
</code></pre>
<p>and pv :</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: kubepv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: testvolume
  hostPath:
    path: &quot;/pvdata&quot;
</code></pre>
<p>After I deploy everything the pvc is pending :</p>
<pre><code>$ kubectl describe  pvc kubepvc
Events:
  Type     Reason              Age   From                         Message
  ----     ------              ----  ----                         -------
  Warning  ProvisioningFailed  6s    persistentvolume-controller  storageclass.storage.k8s.io &quot;testvolume&quot; not found
</code></pre>
<p>Of course the testvolume pv exists :</p>
<pre><code>kubectl get pods,pv,pvc -o wide    
NAME           READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
pod/buggypod   0/1     Pending   0          30m   &lt;none&gt;   &lt;none&gt;   &lt;none&gt;           &lt;none&gt;

NAME                      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE     VOLUMEMODE
persistentvolume/kubepv   10Gi       RWO            Retain           Available           testvolume              3m57s   Filesystem

NAME                            STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE   VOLUMEMODE
persistentvolumeclaim/kubepvc   Pending                                      testvolume     90s   Block
</code></pre>
<p>But I guess the error occurs because the pv type is fileSystem :</p>
<pre><code>$ kubectl describe  pv kubepv
Name:            kubepv
Labels:          &lt;none&gt;
Annotations:     &lt;none&gt;
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    testvolume
Status:          Available
Claim:
Reclaim Policy:  Retain
Access Modes:    RWO
VolumeMode:      Filesystem
Capacity:        10Gi
Node Affinity:   &lt;none&gt;
Message:
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /pvdata
    HostPathType:
Events: 

       &lt;none&gt;
</code></pre>
<p>So, my question is how can I create a Block PV to make everything work?</p>
<p>Thx in advance</p>

<p>Please keep in mind that <code>PersistentVolumeClaim</code> is &quot;Requesting&quot; something from <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">PersistentVolume</a>.</p>
<p>In short, <code>PV</code> must fulfill some <code>PVC</code> requests. In your YAMLs <code>PV</code> fulfills <code>PVC</code> requests like:</p>
<ul>
<li><code>Storage:</code> <code>PV</code> has 10Gi, <code>PVC</code> 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 <code>PV</code> or 10Gi in <code>PVC</code>).</li>
<li><code>AccessMode:</code> Both have <code>ReadWriteOnce</code>.</li>
<li><code>storageClassName:</code> testvolume</li>
</ul>
<p><strong>Misconfiguration</strong></p>
<p>Your <code>PVC</code> is looking for <code>PV</code> with <code>volumeMode: Block</code>. As your current <code>PV</code> don't have it, it <strong>will not be bounded</strong>.</p>
<p><strong>Solution</strong></p>
<p>Add <code>volumeMode: Block</code> to your <code>PV</code> configuration and <code>PVC</code> will bound <code>PV</code>.</p>
<p><strong>Tests</strong></p>
<p>As you described your <code>PV</code> you can find information:</p>
<pre><code>VolumeMode:      Filesystem
</code></pre>
<p>While <code>$ kubectl describe pvc kubepvc</code> have:</p>
<pre><code>VolumeMode:    Block
</code></pre>
<p>When you will add <code>VolumeMode: Block</code> to your <code>PV</code> manifest like below it will work.</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: kubepv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  volumeMode: Block
  storageClassName: testvolume
  hostPath:
    path: &quot;/pvdata&quot;
</code></pre>
<p><strong>Notes</strong></p>
<p>Please keep in mind that <code>volumeMode</code> is <code>immutable</code> field, so you need to recreate this resource, it cannot be edited.</p>
<pre><code>The PersistentVolume &quot;kubepv&quot; is invalid: volumeMode: Invalid value: &quot;Block&quot;: field is immutable
</code></pre>
<p>Regarding <a href="https://kubernetes.io/docs/concepts/storage/storage-classes/" rel="nofollow noreferrer">storageClass</a>, topic is quite wide but in short as <code>storageClassName</code> is the same in <code>PV</code> and <code>PVC</code> it will work (at least on <code>Kubeadm</code>).</p>
<pre><code>$ kubectl get storageclass -A
No resources found
user@kubeadm:~$ kubectl get pv,pvc
NAME                      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM             STORAGECLASS   REASON   AGE
persistentvolume/kubepv   10Gi       RWO            Retain           Bound    default/kubepvc   testvolume              38s

NAME                            STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/kubepvc   Bound    kubepv   10Gi       RWO            testvolume     45s
</code></pre>
<p><strong>Useful Documentation</strong></p>
<ul>
<li><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#raw-block-volume-support" rel="nofollow noreferrer">Raw Block Volume Support
</a></li>
<li><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistent-volume-using-a-raw-block-volume" rel="nofollow noreferrer">PersistentVolume using a Raw Block Volume</a></li>
</ul>
