<p>I am practicing <a href="https://www.katacoda.com/courses/kubernetes/storage-introduction" rel="nofollow noreferrer">k8s</a> on storage topic. I don't understand why step2: <code>PersistentVolume</code> has different storage size when the tutorial configures <code>PersistenVolumeClaim</code> in step3</p>

<p>For example <code>nfs-0001.yaml, nfs-0002.yaml</code>. <code>storage</code>s are <code>2Gi and 5Gi</code></p>

<pre><code>apiVersion: v1
kind: PersistentVolumemetadata:
  name: nfs-0001
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  nfs:
    server: 172.17.0.7
    path: /exports/data-0001
apiVersion: v1
kind: PersistentVolume
metadata:  name: nfs-0002
spec:  
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  nfs:
    server: 172.17.0.7
    path: /exports/data-0002
</code></pre>

<p>Example in step3 : <code>pvc-mysql.yaml, pvc-http.yaml</code></p>

<pre><code>kind: PersistentVolumeClaim
apiVersion: v1metadata:
  name: claim-mysql
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: claim-http
spec:  
  accessModes:
    - ReadWriteOnce  
  resources:
    requests:      
      storage: 1Gi
</code></pre>

<p>And when I check the <code>pv and pvc</code></p>

<pre><code>master $ kubectl get pvc
NAME          STATUS    VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
claim-http    Bound     nfs-0001   2Gi        RWO,RWX                       17m
claim-mysql   Bound     nfs-0002   5Gi        RWO,RWX                       17m
master $ kubectl get pv
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM                 STORAGECLASS   REASON    AGE
nfs-0001   2Gi        RWO,RWX        Recycle          Bound     default/claim-http        19m
nfs-0002   5Gi        RWO,RWX        Recycle          Bound     default/claim-mysql        19m
</code></pre>

<p>Neither <code>1Gi and 3Gi</code> shown up in the terminal. </p>

<p><strong>Question:</strong></p>

<ol>
<li>Where are the <code>1Gi and 3Gi</code>?<br></li>
<li>If they are not used. Is it safe to put arbitrary number to <code>storage</code> in <code>PersistenVolumeClaim</code> yaml?</li>
</ol>

<p>You need to understand the difference between PV and PVC's. PVC is a declaration of stroage which that at some point become available for application to use and that is not the actual size of volume allocated.</p>

<p>PV's are the actual volume allocated at the time on the disk and ready to use. In order to use these PVs user needs to create PersistentVolumeClaims which is nothing but a request for PVs. A claim must specify the access mode and storage capacity, once a claim is created PV is automatically bound to this claim.</p>

<p>In your case, you have PV size of 5 and 3 GB respectively and you have started two PVC's with 3 and 1 GB respectively with <code>accessmode: ReadWriteOnce</code> that means there can be only one PV is attached to the one PVC. </p>

<p>Now the capacity of the PV available is the larger than requested and hence it allocated the larger size PV to the PVC.</p>

<blockquote>
  <p><code>PVC.spec.capacity</code> is user's request for storage, "I want 10 GiB volume". <code>PV.spec.capacity</code> is actual size of the PV. PVC can bind to a bigger PV when there is no smaller available PV, so the user can get actually more than he wants.</p>
</blockquote>

<p>Similarly, dynamic provisioning works typically in bigger chunks. So if user asks for 0.5GiB in a PVC, he will get 1 GiB PV because that's the smallest one that AWS can provision.</p>

<p>There is nothing wrong about it. Also, you should not put any random number in PVC size, it should be well calculated according to your application need and scaling.</p>
