Can two persistent volume claims be bound to the same persistent volume?

16,493 views
Skip to first unread message

Qian Zhang

unread,
Aug 1, 2016, 2:31:37 AM8/1/16
to Containers at Google
Hi,

If I have one persistent volume (100GB) created in Kubernetes, can I create two persistent volume claims (50GB for each) to use this persistent volume? It seems I can not do it with NFS type of persistent volume, i.e., once an NFS persistent volume is partially used by a persistent volume claim, it can not be used by any other persistent volume claims even it still has free capacity. But I am not sure if the other type of persistent volumes (Ceph, Glusterfs, etc.) have the same behavior.

Tim Hockin

unread,
Aug 1, 2016, 2:34:43 AM8/1/16
to Containers at Google
A PersistentVolume (PV) is an atomic abstraction. You can not
subdivide it across multiple claims. You can make a PV that uses the
same backing medium, if the driver allows it. E.g. consider NFS. If
your NFS server has 150 GB free, nothing stops you from making 2 PVs
each of size 100GB. We can't validate that. It might be bad for your
users, but that is a decision you have to make as a cluster admin.
> --
> You received this message because you are subscribed to the Google Groups
> "Containers at Google" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-contain...@googlegroups.com.
> To post to this group, send email to google-c...@googlegroups.com.
> Visit this group at https://groups.google.com/group/google-containers.
> For more options, visit https://groups.google.com/d/optout.

Qian Zhang

unread,
Aug 1, 2016, 2:40:34 AM8/1/16
to google-c...@googlegroups.com
Thanks Tim! So a PV can only be used by a single PVC no matter what its type is.

And can you please clarify a bit about "You can make a PV that uses the same backing medium, if the driver allows it"? I do not quite understand about it, I think a PV should always use a single backing medium rather than multiple, right?


Thanks,
Qian Zhang

You received this message because you are subscribed to a topic in the Google Groups "Containers at Google" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-containers/6A1ZwSYkG8I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-contain...@googlegroups.com.

Tim Hockin

unread,
Aug 1, 2016, 2:46:04 AM8/1/16
to Containers at Google
A PV uses a single backing medium, but multiple PVs might share that
medium. Consider "thin" block devices which allocate actual space on
demand. You might over-commit your storage system. Consider NFS
which can have multiple exports on the same filesystem. You might
over-commit your NFS server.

Not saying it's a great idea, just that it is possible.

Qian Zhang

unread,
Aug 1, 2016, 2:54:58 AM8/1/16
to google-c...@googlegroups.com
Yeah, actually I am also a bit confused about the capacity user defined in PV and PVC, who will be responsible for enforcing it? E.g., I have an NFS server which has 10GB free, and I create a PV (1GB) and PVC (1GB), and create a pod uses that PVC. So in the pod, can I only write 1GB into the mounted NFS directory? If so, who enforces it?

And if a PV can only be used by a single PVC, why does user need to define the PVC's capacity when creating the PVC? I think we should not ask user to define it, i.e., all the capacity of the PV should be used.



Thanks,
Qian Zhang

Tim Hockin

unread,
Aug 1, 2016, 3:01:07 AM8/1/16
to Containers at Google
Nobody enforces it yet (well, WE don't, but the storage system behind
us might). It's a way to match user needs (PVC) to available
resources (PV).

> why does user need to define the PVC's capacity when creating the PVC?

If the user needs 100GB and I give them a PV with 2 GB, they will not
be happy. They have to specify how much they nee so we can bind (or
provision) a PV for them.

Qian Zhang

unread,
Aug 1, 2016, 3:13:51 AM8/1/16
to google-c...@googlegroups.com
I am curious how the storage system behind us does the enforcement, e.g., will we let NFS server know the capacity of PV is 1GB, and NFS server can guarantee the pod using that PV can not write more than 1GB?


Thanks,
Qian Zhang

Tim Hockin

unread,
Aug 1, 2016, 3:32:34 AM8/1/16
to Containers at Google
If your NFS system supports that, that is one way ti could be done, yes.

Qian Zhang

unread,
Aug 1, 2016, 3:51:36 AM8/1/16
to google-c...@googlegroups.com
Got it, thanks Tim!

BTW, is there any best practice to use PV of NFS type? E.g., there is an NFS server which has only one export, should admin only create 1 PV for it? Or it is also OK to create multiple PVs?


Thanks,
Qian Zhang

Tim Hockin

unread,
Aug 1, 2016, 3:52:41 AM8/1/16
to Containers at Google
YOu can create multiple PVs with the same NFS export, as long as that
is acceptable to you :)

Stephen Eaton

unread,
Aug 24, 2018, 12:39:33 PM8/24/18
to Kubernetes user discussion and Q&A
I tried creating two PV's of 10Gi both pointing at the same NFS of 1TB. I also create 2 PVCs for the same StorageClass also of 10Gi.

The problem is that when I add a file to on the the PVs the same file is present on the other PV.

What I would like to be able to do it to create to separate 'partitions' (or locaigical separation) so that one PV does not share the data of the other PV - is this possible?

Tim Hockin

unread,
Aug 24, 2018, 12:55:17 PM8/24/18
to Kubernetes user discussion and Q&A
If you pointed them at the same NFS export (server + path) then it's
expected that they would see each other's changes. You can either
create another export on the server or mount a sub-dir of that export
(e.g. export /home, but mount /home/you vs /home/me) or you can use
k8s' `subPath` field on the pods to mount different subdirs.
> You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
> To post to this group, send email to kubernet...@googlegroups.com.
> Visit this group at https://groups.google.com/group/kubernetes-users.

Michelle Au

unread,
Aug 24, 2018, 1:09:34 PM8/24/18
to Kubernetes user discussion and Q&A
You can try the nfs-client provisioner to dynamically create subdirectories on a single NFS server:
Reply all
Reply to author
Forward
0 new messages