Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to bound a Persistent volume claim with a gcePersistentDisk?

I would like to bound PersistentVolumeClaim with a gcePersistentDisk PersistentVolume. Below the steps I did for getting that:

1. Creation of the gcePersistentDisk:

gcloud compute disks create --size=2GB --zone=us-east1-b gce-nfs-disk

2. Definition the PersistentVolume and the PersistentVolumeClaim

# 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"}
like image 477
Amine Jallouli Avatar asked Nov 19 '17 15:11

Amine Jallouli


People also ask

How do I bind a persistentvolumeclaim to a specific persistent volume?

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.

How to use Google persistent disk as GKE persistent volumes?

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.

What are persistent volumes and claims in Kubernetes?

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.

How do I create a persistent volume in GKE?

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.


1 Answers

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.

like image 164
Amine Jallouli Avatar answered Oct 02 '22 07:10

Amine Jallouli