1

I'm studying k8s and got a question about PV and PVC binding.

PVC defines the specs it wants (capacity, access mode etc..) in the YAML file and find appropriate PV in the cluster to bind each other.

Here, let's say our PVC wants at least 5GB capacity and RWO (ReadWriteOnce) mode.

And there are two PVs

  • PV1: 5GB, RWO
  • PV2: 10GB, RWO

which one would bind to the PVC? Both of them meets the spec of PVC.

Plus, what if we the pod fails and recreated?

If PV works as we want(in retain mode), I think the same PV should be bound to the PVC(pod) again to preserve the data. Does k8s guarantees this work?

If there's something ambiguous in my question, please let me know.

Thank you.

1 Answers1

0

which one would bind to the PVC? Both of them meets the spec of PVC.

You cannot specify "at least 5 GiB" of storage. The number provided in the PVC specification will always be a concrete value and a PV that better fits the requirement should be the one bound. In this case, it will be PV1: 5GiB RWO.

If PV works as we want(in retain mode), I think the same PV should be bound to the PVC(pod) again to preserve the data. Does k8s guarantees this work

Yes, it is guaranteed. However, you will first need to ensure that you manually 'bind' the PVC to the PV using reservation.

Also, understand that a pod dying/restarting has no effect on a PVC->PV mapping. That is the entire point of having PersistentVolumes in the first place, they should be isolated from crashes in the pods that mount them. As soon as the pod comes back up, the PVC will be mounted as a volume again, and everything will be restored.

You can always learn more from the official documentation.

zer0
  • 2,153
  • 10
  • 12
  • "that better fits the requirement should be the one bound" --- where exactly this is explained? I always thought that an arbitrary PV that fits requirements would be chosen without evaluating which is "better". – zerkms Jul 07 '22 at 02:42
  • There are many criteria that decide this and the documentation linked provides all the details. They have been distributed into sections. The bottom line is, _**the clearer you describe your requirements in the PVC, the higher the chances are that you will match the 'best' PV**_. The best bet would be to specify the most you can, and the size will be used to match the closest PV (in order to waste less space). – zer0 Jul 07 '22 at 03:28