Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
833 views
in Technique[技术] by (71.8m points)

kubernetes - Can a PVC be bound to a specific PV?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  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
    
    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
    
  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. 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
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...