Kubernetes NFS Persistent Volumes - multiple claims on same volume? Claim stuck in pending?

后端 未结 4 1806
遥遥无期
遥遥无期 2020-12-17 08:51

Use case:

I have a NFS directory available and I want to use it to persist data for multiple deployments & pods.

I have created a PersistentVolume<

相关标签:
4条回答
  • 2020-12-17 09:09

    From: https://docs.openshift.org/latest/install_config/storage_examples/shared_storage.html

    As Baroudi Safwen mentioned, you cannot bind two pvc to the same pv, but you can use the same pvc in two different pods.

    volumes:
    - name: nfsvol-2
      persistentVolumeClaim:
        claimName: nfs-pvc-1 <-- USE THIS ONE IN BOTH PODS   
    
    0 讨论(0)
  • 2020-12-17 09:13

    Basically you can't do what you want, as the relationship PVC <--> PV is one-on-one.

    If NFS is the only storage you have available and would like multiple PV/PVC on one nfs export, use Dynamic Provisioning and a default storage class.

    It's not in official K8s yet, but this one is in the incubator and I've tried it and it works well: https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client

    This will enormously simplify your volume provisioning as you only need to take care of the PVC, and the PV will be created as a directory on the nfs export / server that you have defined.

    0 讨论(0)
  • 2020-12-17 09:26

    a few points on dynamic provisioning..

    using dynamic provisioning of nfs prevents you for changing any of the default nfs mount options. On my platform this uses rsize/wsize of 1M. this can cause huge problems in some applications using small files or block reading. (I've just hit this issue in a big way)

    dynamic is a great option if it suits your needs. I'm now stuck with creating 250 pv/pvc pairs for my application that was being handled by dynamic due to the 1-1 relationship.

    0 讨论(0)
  • 2020-12-17 09:28

    A persistent volume claim is exclusively bound to a persistent volume.
    You cannot bind 2 pvc to the same pv.

    I guess you are interested in the dynamic provisioning. I faced this issue when I was deploying statefulsets, which require dynamic provisioning for pods. So you need to deploy an NFS provisioner in your cluster, the NFS provisioner(pod) will have access to the NFS folder(hostpath), and each time a pod requests a volume, the NFS provisioner will mount it in the NFS directory on behalf of the pod.
    Here is the github repository to deploy it:
    https://github.com/kubernetes-incubator/external-storage/tree/master/nfs/deploy/kubernetes
    You have to be careful though, you must ensure the nfs provisioner always runs on the same machine where you have the NFS folder by making use of the node selector since you the volume is of type hostpath.

    0 讨论(0)
提交回复
热议问题