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
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
The obtained PersistentVolume is a volume on the disk of the node I created on Google Container Engine. So, have I missed something?
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"}
There are several ways to bind a PersistentVolumeClaim to a specific PersistentVolume. For example, the following YAML manifest creates a new PersistentVolume and PersistentVolumeClaim, and then binds the claim to the volume using a claimRef, which ensures that the PersistentVolume can only be bound to that PersistentVolumeClaim.
Now that we know the two ways to use google persistent disk as GKE persistent volumes, we will look at using the persistent volume in a pod. To mount a persistent volume to the pod, we use the Persistent volume claim name in the volumes section, and we use the volume name in the volumeMounts section with the container path to mount.
This page provides an overview of persistent volumes and claims in Kubernetes, and their use with Google Kubernetes Engine (GKE). This page focuses on storage backed by Compute Engine persistent disks. PersistentVolumes PersistentVolumeresources are used to manage durable storage in a cluster.
Create a Persistent Volume using PVC on GKE To create a persistent volume you need to create a Persistent Volume claim. persistentVolumeClaim is the way to request storage based on a storage class and use it with a pod. The pod to Persistent volume mapping happens through PVC.
I found the solution.
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
I hope it will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With