K8S PersistenVolume and PersistentVolumeClaim K8S PersistenVolume and PersistentVolumeClaim kubernetes kubernetes

K8S PersistenVolume and PersistentVolumeClaim


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.

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.

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 accessmode: ReadWriteOnce that means there can be only one PV is attached to the one PVC.

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

PVC.spec.capacity is user's request for storage, "I want 10 GiB volume". PV.spec.capacity 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.

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.

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.