如何将永久卷声明与gcePersistentDisk绑定? [英] how to bound a Persistent volume claim with a gcePersistentDisk?
问题描述
我想用gcePersistentDisk PersistentVolume绑定PersistentVolumeClaim.在我为达到该目的而执行的步骤下面:
I would like to bound PersistentVolumeClaim with a gcePersistentDisk PersistentVolume. Below the steps I did for getting that:
gcloud compute disks create --size=2GB --zone=us-east1-b gce-nfs-disk
# pv-pvc.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: gce-nfs-disk
fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
labels:
app: test
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
运行kubectl apply -f pv-pvc.yml
后,nfs-pvc
未与nfs-pv
绑定.实际上,下面是我拥有的PersistentVolume和PersistentVolumeClaim的列表:
After running kubectl apply -f pv-pvc.yml
, the nfs-pvc
is not bound with nfs-pv
. In fact, below is the list of the PersistentVolume and PersistentVolumeClaim I have:
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv 2Gi RWO Retain Available 30s
pvc-16e4cdf2-cd3d-11e7-83ae-42010a8e0243 2Gi RWO Delete Bound default/nfs-pvc standard 26s
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nfs-pvc Bound pvc-16e4cdf2-cd3d-11e7-83ae-42010a8e0243 2Gi RWO standard 59s
获得的PersistentVolume是我在Google Container Engine上创建的节点的磁盘上的卷. 所以,我错过了什么吗?
The obtained PersistentVolume is a volume on the disk of the node I created on Google Container Engine. So, have I missed something?
PS:kubernetes的版本
PS: the version of kubernetes
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.3", GitCommit:"f0efb3cb883751c5ffdbe6d515f3cb4fbe7b7acd", GitTreeState:"clean", BuildDate:"2017-11-08T18:39:33Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"7+", GitVersion:"v1.7.8-gke.0", GitCommit:"a7061d4b09b53ab4099e3b5ca3e80fb172e1b018", GitTreeState:"clean", BuildDate:"2017-10-10T18:48:45Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
推荐答案
我找到了解决方案.
在PV和PVC的新定义下面:
Below the new definitions of the PV and PVC:
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
labels:
app: test # the label has been added to make sure the bounding is working as expected
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: gce-nfs-disk
fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
labels:
app: test
spec:
accessModes:
- ReadWriteOnce
storageClassName: "" # the storageClassName has to be specified
resources:
requests:
storage: 2Gi
selector:
matchLabels:
app: test
在进行了这些修改之后,这就是有效的边界:
After these modifications, this is the bounding worked:
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nfs-pvc Bound nfs-pv 2Gi RWO 8s
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
nfs-pv 2Gi RWO Retain Bound default/nfs-pvc 22m
我希望它会有所帮助.
这篇关于如何将永久卷声明与gcePersistentDisk绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!