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
再次,这正常吗?
在多个部署/吊舱之间使用/重复使用共享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.
它还没有在官方的K8中使用,但是这已经在孵化器中了,我已经尝试过了,并且效果很好:
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屋!