PVC 可以绑定到特定的 PV 吗? [英] Can a PVC be bound to a specific PV?
问题描述
k8s 维护者在 https://github.com/kubernetes 中讨论了这个问题/kubernetes/issues/7438#issuecomment-97148195:
<块引用><块引用>允许用户要求特定的 PV 打破了他们之间的分离
我不买那个.我们允许用户选择一个节点.这不是常见的案例,但它存在是有原因的.
结局如何?拥有 >1 PV 和 PVC 的预期方式是什么,就像 https://github.com/kubernetes/kubernetes/tree/master/examples/nfs?
我们使用 NFS,而 PersistentVolume 是一个方便的抽象,因为我们可以将 server
IP 和 path
保留在那里.但是 PersistentVolumeClaim 可以获取任何足够大小的 PV,从而防止 path
重用.
可以在 PVC spec
块中设置 volumeName
(参见 https://github.com/kubernetes/kubernetes/pull/7529)但没有区别.
今天有一种方法可以将 PV 预先绑定到 PVC,下面是一个示例:
- 创建一个 PV 对象,其 ClaimRef 字段引用您随后将创建的 PVC:
$ kubectl create -f pv.yaml持久卷pv0003"创造
其中
pv.yaml
包含:apiVersion: v1种类:持久卷元数据:名称:pv0003规格:存储类名称:"容量:存储:5Gi访问模式:- 读写一次持久卷回收策略:保留索赔参考:命名空间:默认名称:我的主张nfs:路径:/tmp服务器:172.17.0.2
- 然后创建具有相同名称的 PVC:
种类:PersistentVolumeClaimapi版本:v1元数据:名称:我的主张规格:存储类名称:"访问模式:- 读写一次资源:要求:存储:5Gi
- PV 和 PVC 应该立即绑定:
$ kubectl get pvc名称 状态 卷容量 访问模式 年龄myclaim 绑定 pv0003 5Gi RWO 4s$ ./cluster/kubectl.sh 获取 pv名称 容量 访问模式 状态 索赔 原因 年龄pv0003 5Gi RWO 绑定默认值/myclaim 57s
This was discussed by k8s maintainers in https://github.com/kubernetes/kubernetes/issues/7438#issuecomment-97148195:
Allowing users to ask for a specific PV breaks the separation between them
I don't buy that. We allow users to choose a node. It's not the common case, but it exists for a reason.
How did it end? What's the intended way to have >1 PV's and PVC's like the one in https://github.com/kubernetes/kubernetes/tree/master/examples/nfs?
We use NFS, and PersistentVolume is a handy abstraction because we can keep the server
IP and the path
there. But a PersistentVolumeClaim gets any PV with sufficient size, preventing path
reuse.
Can set volumeName
in a PVC spec
block (see https://github.com/kubernetes/kubernetes/pull/7529) but it makes no difference.
There is a way to pre-bind PVs to PVCs today, here is an example showing how:
- Create a PV object with a ClaimRef field referencing a PVC that you will subsequently create:
$ kubectl create -f pv.yaml persistentvolume "pv0003" created
where
pv.yaml
contains:apiVersion: v1 kind: PersistentVolume metadata: name: pv0003 spec: storageClassName: "" capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain claimRef: namespace: default name: myclaim nfs: path: /tmp server: 172.17.0.2
- Then create the PVC with the same name:
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: myclaim spec: storageClassName: "" accessModes: - ReadWriteOnce resources: requests: storage: 5Gi
- The PV and PVC should be bound immediately:
$ kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESSMODES AGE myclaim Bound pv0003 5Gi RWO 4s $ ./cluster/kubectl.sh get pv NAME CAPACITY ACCESSMODES STATUS CLAIM REASON AGE pv0003 5Gi RWO Bound default/myclaim 57s
这篇关于PVC 可以绑定到特定的 PV 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!