how to bound a Persistent volume claim with a gcePersistentDisk?

后端 未结 2 581
温柔的废话
温柔的废话 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.

    0 讨论(0)
  • 2021-02-03 15:11

    With PersistentVolumeClaim, you don't need to create PersistentVolume objects or gcePersistentDisk. Instead, create only a PVC and Kubernetes automatically creates a PV object that references the backing storage.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: nfs-pvc
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: ssd-sc  # specify the storage class created below
      resources:
        requests:
          storage: 10Gi
    

    Create a StorageClass so it knows which backing storage to use. You can specify that it retains the storage (reclaimPolicy: Retain) if you delete the PVC and the storage type (type: pd-ssd).

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: ssd-sc 
    provisioner: kubernetes.io/gce-pd
    reclaimPolicy: Retain # Retain storage even if we delete PVC
    parameters:
      type: pd-ssd # ssd
    
    0 讨论(0)
提交回复
热议问题