how to bound a Persistent volume claim with a gcePersistentDisk?

后端 未结 2 582
温柔的废话
温柔的废话 2021-02-03 14:09

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

1. Creation of the gcePersistentDisk:

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-03 14:59

    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.

提交回复
热议问题