PVC可以绑定到特定的PV吗? [英] Can a PVC be bound to a specific PV?

查看:1572
本文介绍了PVC可以绑定到特定的PV吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

k8s维护人员在 https://github.com/kubernetes中进行了讨论/kubernetes/issues/7438#issuecomment-97148195 :

允许用户要求特定的PV会打破他们之间的分隔

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.

它是如何结束的?像 https://中的那样,具有> 1个PV和PVC的预期方式是什么? github.com/kubernetes/kubernetes/tree/master/examples/nfs ?

我们使用NFS,而PersistentVolume是一个方便的抽象,因为我们可以将server IP和path保留在那里.但是PersistentVolumeClaim可以获取具有足够大小的 any PV,从而防止path重用.

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.

可以在PVC spec块中设置volumeName(请参见 https://github. com/kubernetes/kubernetes/pull/7529 ),但没有区别.

Can set volumeName in a PVC spec block (see https://github.com/kubernetes/kubernetes/pull/7529) but it makes no difference.

推荐答案

今天,有一种方法可以将PV预绑定到PVC,下面是一个示例,展示了如何:

There is a way to pre-bind PVs to PVCs today, here is an example showing how:

1)创建一个带有ClaimRef字段的PV对象,该字段引用随后将要创建的PVC:

1) Create a PV object with a ClaimRef field referencing a PVC that you will subsequently create:

$ kubectl create -f pv.yaml
persistentvolume "pv0003" created

其中pv.yaml包含:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  storageClassName: ""
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  claimRef:
    namespace: default
    name: myclaim
  nfs:
    path: /tmp
    server: 172.17.0.2

2)然后创建具有相同名称的PVC:

2) Then create the PVC with the same name:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  storageClassName: ""
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

3)PV和PVC应该立即绑定:

3) 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆