Kubernetes NFS 持久卷 - 在同一卷上有多个声明?索赔卡在等待中? [英] Kubernetes NFS Persistent Volumes - multiple claims on same volume? Claim stuck in pending?
问题描述
用例:
我有一个可用的 NFS 目录,我想用它来为多个部署保存数据 &豆荚.
I have a NFS directory available and I want to use it to persist data for multiple deployments & pods.
我创建了一个PersistentVolume
:
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
nfs:
server: http://mynfs.com
path: /server/mount/point
我希望多个部署能够使用这个PersistentVolume
,所以我对需要的理解是我需要创建多个PersistentVolumeClaims
,它们都指向这个PersistentVolume
.
I want multiple deployments to be able to use this PersistentVolume
, so my understanding of what is needed is that I need to create multiple PersistentVolumeClaims
which will all point at this PersistentVolume
.
kind: PersistentVolumeClaim
apiVersion: v1
metaData:
name: nfs-pvc-1
namespace: default
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 50Mi
我相信这会在 PersistentVolume
上创建一个 50MB 的声明.当我运行 kubectl get pvc
时,我看到:
I believe this to create a 50MB claim on the PersistentVolume
. When I run kubectl get pvc
, I see:
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
nfs-pvc-1 Bound nfs-pv 10Gi RWX 35s
我不明白为什么我看到的是 10Gi 容量,而不是 50Mi.
I don't understand why I see 10Gi capacity, not 50Mi.
当我更改 PersistentVolumeClaim
部署 yaml 以创建一个名为 nfs-pvc-2
的 PVC 时,我得到了这个:
When I then change the PersistentVolumeClaim
deployment yaml to create a PVC named nfs-pvc-2
I get this:
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
nfs-pvc-1 Bound nfs-pv 10Gi RWX 35s
nfs-pvc-2 Pending 10s
PVC2 永远不会绑定到 PV.这是预期的行为吗?我可以有多个 PVC 指向同一个 PV 吗?
PVC2 never binds to the PV. Is this expected behaviour? Can I have multiple PVCs pointing at the same PV?
当我删除 nfs-pvc-1
时,我看到同样的事情:
When I delete nfs-pvc-1
, I see the same thing:
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
nfs-pvc-2 Pending 10s
再说一遍,这正常吗?
在多个部署/Pod 之间使用/重用共享 NFS 资源的合适方法是什么?
What is the appropriate way to use/re-use a shared NFS resource between multiple deployments / pods?
推荐答案
基本上你不能为所欲为,因为 PVC <--> PV 是一对一的关系.
Basically you can't do what you want, as the relationship PVC <--> PV is one-on-one.
如果 NFS 是您唯一可用的存储,并且希望在一个 nfs 导出上有多个 PV/PVC,请使用动态配置和默认存储类.
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.
它还没有在正式的 K8s 中,但这个在孵化器中,我已经尝试过并且运行良好:https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client
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
这将极大地简化您的卷配置,因为您只需要处理 PVC,并且 PV 将创建为您定义的 nfs 导出/服务器上的目录.
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.
这篇关于Kubernetes NFS 持久卷 - 在同一卷上有多个声明?索赔卡在等待中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!