When capacity of pvc is smaller than capacity of pc

Cluster information:

Kubernetes version: v1.16.2
Host OS: Mac 10.14

apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-storage
spec:
  storageClassName: ssd
  capacity:
		storage: 20Gi
	accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/mongo
    type: DirectoryOrCreate 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: ssd

I create a PV with 20G and a PVC claiming 10G. The PVC bound to PV successfully. When I check the PVC using kubectl get pvc or kubectl describe pvc ..., the capacity is 20G not 10G. In fact, I cannot find anything reflecting that I only request 10G. When I attach the pvc to a pod, does the container in the pod have access to a 10G space or 20G space?

I think it will have access to all the pv.

The PVC will be used to match something that satisfy it, but if only volumes with more space are available, it will be assigned to those. This is pretty much on purpose (so PVC is not coupled with pvs), and documented, I think.

Also, this is very easy to test: use more than requested. Then, you will see :). My bet is that you can use the entire PV bounded to the PVC. But let us know :slight_smile:

Thank you. I guess you are right.

I did an experiment: create 1 * 20G pv and 2 * 10G pvc. The first pvc claimed the pv and second pvc would stay PENDING until I created another pv which satisfied it.

Conclusion: a pvc will fully obtain a pv not part of it. whatever in the requests is just a filter for pvc to look for a pv.

1 Like

Cool!

I think the doc might say that too, but maybe not that loud? Or maybe it doesn’t say it :smiley: