Creating a PersistentVolumeClaim

Explore this Page

Overview

This document provides step-by-step guidance on creating PersistentVolumeClaims (PVCs) for different types of storage classes in a Kubernetes cluster. The configurations focus on the following storage types:

  • Replicated PV Mayastor
  • Local PV Hostpath
  • Local PV LVM
  • Local PV ZFS

Each section includes example YAML manifests and corresponding kubectl commands to help you create PVCs effectively.

Before proceeding, ensure that the respective StorageClass objects are already configured, as outlined in the earlier setup steps. The PVC configurations provided here are intended to work seamlessly with those predefined storage classes.

Creating a PVC for Replicated PV Mayastor

  • Before proceeding, ensure that you have already created a suitable Mayastor-based StorageClass as described in the earlier configuration steps. In this example, we use a placeholder name mayastor-1 for the StorageClass. Be sure to replace it with the name of your actual StorageClass when following along.
  • The example PVC is named ms-volume-claim. While this name is suggested for consistency throughout the guide, you may choose a different name based on your workload requirements.
  1. Create the PVC directly using a kubectl command and inline YAML. The following example requests a 1Gi volume with ReadWriteOnce access mode.

    Copy
    Create PVC via kubectl
    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: ms-volume-claim
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: mayastor-1
    EOF
  2. The following is the YAML manifest for the PersistentVolumeClaim, which you can apply using kubectl or save as a standalone file.

    Copy
    YAML
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: ms-volume-claim
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: INSERT_YOUR_STORAGECLASS_NAME_HERE

    Replace INSERT_YOUR_STORAGECLASS_NAME_HERE with the actual name of your Replicated PV Mayastor StorageClass.

    If your StorageClass is configured with the WaitForFirstConsumer volume binding mode (as recommended), the volume will not be provisioned immediately upon PVC creation. Instead, the volume will be bound only when a pod requests it. This approach ensures that the volume is provisioned on a node where the pod is scheduled, supporting optimal placement and efficiency.

Creating a PVC for Local PV Hostpath

The PVC is used by Pods to request Local PV Hostpath from the DataCore Puls8 Dynamic Local PV provisioner.

  1. Save the following PVC configuration as local-hostpath-pvc.yaml:

    Copy
    PVC Configuration
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: local-hostpath-pvc
    spec:
      storageClassName: puls8-hostpath
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 5G
  2. Create the PVC.

    Copy
    Create PVC
    kubectl apply -f local-hostpath-pvc.yaml
  3. Verify the status of the PVC.

    Copy
    Verify PVC
    kubectl get pvc local-hostpath-pvc

The output will indicate that the PVC status is Pending, meaning it has not yet been utilized by an application Pod.

Copy
Sample Output
NAME                 STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS       AGE
local-hostpath-pvc   Pending                                      puls8-hostpath     3m7s

Creating a PVC for Local PV LVM

  1. To define a PVC that utilizes the Local PV LVM storage class, save the following YAML configuration:

    Copy
    YAML Configuration
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
     name: csi-lvmpv
    spec:
     storageClassName: puls8-lvmpv
     accessModes:
       - ReadWriteOnce
     resources:
       requests:
         storage: 4Gi
  2. If immediate binding is enabled in the storage class, you can check the corresponding LVM volume immediately. Run the following command to check the LVM volume (LV) in Kubernetes:

    Copy
    Retrieve Details of the Provisioned LVM Volume
    $ kubectl get lv -n puls8
    Copy
    Sample Output
    NAME                                       VG           NODE           SIZE         STATUS   FILESYSTEM   AGE
    pvc-5a2c3d48-1b2c-11eb-adc1-0242ac120002   lvm-pool    lvm-node1      10737418240   Ready    ext4         4s
  3. To describe the LVM volume, use the following command:

    Copy
    Display Detailed Information about the ZFS Volume
    $ kubectl describe lv pvc-34133838-0d0d-11ea-96e3-42010a800114 -n puls8
    Copy
    Sample Output
    Name:         pvc-34133838-0d0d-11ea-96e3-42010a800114
    Namespace:    puls8
    Labels:       kubernetes.io/nodename=lvmpv-node1
    Annotations:  <none>
    API Version:  openebs.io/v1alpha1
    Kind:         LVMVolume
    Metadata:
      Creation Timestamp:  2019-11-22T09:49:29Z
      Finalizers:
        lvm.openebs.io/finalizer
      Generation:        1
      Resource Version:  2881
      Self Link:         /apis/openebs.io/v1alpha1/namespaces/puls8/lvmvolumes/pvc-34133838-0d0d-11ea-96e3-42010a800114
      UID:               60bc4df2-0d0d-11ea-96e3-42010a800114
    Spec:
      Capacity:       4294967296
      Fs Type:        lvm
      Owner Node ID:  lvmpv-node1
      VG Name:        lvmpv-pool
      Thin Provision: false
    Status:
      State: Ready
    Events:           <none>
  4. To verify the logical volume creation, log in to the node lvm-node1 and execute the following command:

    Copy
    List all LVM Logical Volumes and their Details
    lvs list
    Copy
    Sample Output
    LV                                        VG        Attr       LSize  
    pvc-5a2c3d48-1b2c-11eb-adc1-0242ac120002   lvm-pool  -wi-ao---- 10.00G                                                    

Creating a PVC for Local PV ZFS

  1. To define a PVC that utilizes the Local PV ZFS storage class, save the following YAML configuration:

    Copy
    YAML Configuration
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: csi-zfspv
    spec:
      storageClassName: puls8-zfspv
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 4Gi

    When this PVC is created, the volume size will be rounded off to the nearest Mi or Gi notation.

  2. If immediate binding is enabled in the storage class, you can check the corresponding ZFS volume immediately. However, for late binding, verification should be performed after the pod has been scheduled. Verify the ZFS volume (ZV) in Kubernetes:

    Copy
    Retrieve Details of the Provisioned ZFS Volume
    kubectl get zv -n puls8
    Copy
    Sample Output
    NAME                                       ZPOOL        NODE           SIZE         STATUS   FILESYSTEM   AGE
    pvc-34133838-0d0d-11ea-96e3-42010a800114   zfspv-pool   zfspv-node1    4294967296   Ready    zfs          4s
  3. To describe the ZFS volume, use the following command:

    Copy
    Display Detailed Information about the ZFS Volume
    kubectl describe zv pvc-34133838-0d0d-11ea-96e3-42010a800114 -n puls8
    Copy
    Sample Output
    Name:         pvc-34133838-0d0d-11ea-96e3-42010a800114
    Namespace:    puls8
    Labels:       kubernetes.io/nodename=zfspv-node1
    Annotations:  <none>
    API Version:  openebs.io/v1alpha1
    Kind:         ZFSVolume
    Metadata:
      Creation Timestamp:  2019-11-22T09:49:29Z
      Finalizers:
        zfs.openebs.io/finalizer
      Generation:        1
      Resource Version:  2881
      Self Link:         /apis/openebs.io/v1alpha1/namespaces/puls8/zfsvolumes/pvc-34133838-0d0d-11ea-96e3-42010a800114
      UID:               60bc4df2-0d0d-11ea-96e3-42010a800114
    Spec:
      Capacity:       4294967296
      Compression:    off
      Dedup:          off
      Fs Type:        zfs
      Owner Node ID:  zfspv-node1
      Pool Name:      zfspv-pool
      Recordsize:     4k
      Volume Type:    DATASET
    Status:
      State: Ready
    Events:           <none>

    The ZFS driver will create a ZFS dataset (or ZVOL, depending on the fstype specified in the storage class) on the node zfspv-node1 within the specified ZFS pool. The dataset name will match the persistent volume (PV) name.

  4. Verifying the Volume on the Node - To confirm the dataset creation, log in to the node zfspv-node1 and execute the following command:

    Copy
    List all ZFS Datasets and their Usage Details
    zfs list
    Copy
    Sample Output
    NAME                                                  USED  AVAIL  REFER  MOUNTPOINT
    zfspv-pool                                            444K   362G    96K  /zfspv-pool
    zfspv-pool/pvc-34133838-0d0d-11ea-96e3-42010a800114    96K  4.00G    96K  legacy

Learn More