Creating a PersistentVolumeClaim
Explore this Page
- Overview
- Creating a PVC for Replicated PV Mayastor
- Creating a PVC for Local PV Hostpath
- Creating a PVC for Local PV LVM
- Creating a PVC for Local PV ZFS
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.
-
Create the PVC directly using a
kubectl
command and inline YAML. The following example requests a 1Gi volume withReadWriteOnce
access mode.CopyCreate PVC via kubectlcat <<EOF | kubectl create -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ms-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: mayastor-1
EOF -
The following is the YAML manifest for the PersistentVolumeClaim, which you can apply using
kubectl
or save as a standalone file.CopyYAMLapiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ms-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: INSERT_YOUR_STORAGECLASS_NAME_HEREReplace
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.
-
Save the following PVC configuration as
local-hostpath-pvc.yaml
:CopyPVC Configurationkind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: local-hostpath-pvc
spec:
storageClassName: puls8-hostpath
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5G -
Create the PVC.
-
Verify the status of the PVC.
The output will indicate that the PVC status is Pending, meaning it has not yet been utilized by an application Pod.
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
local-hostpath-pvc Pending puls8-hostpath 3m7s
Creating a PVC for Local PV LVM
-
To define a PVC that utilizes the Local PV LVM storage class, save the following YAML configuration:
CopyYAML Configurationkind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-lvmpv
spec:
storageClassName: puls8-lvmpv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi -
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:
CopySample OutputNAME VG NODE SIZE STATUS FILESYSTEM AGE
pvc-5a2c3d48-1b2c-11eb-adc1-0242ac120002 lvm-pool lvm-node1 10737418240 Ready ext4 4s -
To describe the LVM volume, use the following command:
CopyDisplay Detailed Information about the ZFS Volume$ kubectl describe lv pvc-34133838-0d0d-11ea-96e3-42010a800114 -n puls8
CopySample OutputName: 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> -
To verify the logical volume creation, log in to the node
lvm-node1
and execute the following command:CopySample OutputLV VG Attr LSize
pvc-5a2c3d48-1b2c-11eb-adc1-0242ac120002 lvm-pool -wi-ao---- 10.00G
Creating a PVC for Local PV ZFS
-
To define a PVC that utilizes the Local PV ZFS storage class, save the following YAML configuration:
CopyYAML Configurationkind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-zfspv
spec:
storageClassName: puls8-zfspv
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4GiWhen this PVC is created, the volume size will be rounded off to the nearest Mi or Gi notation.
-
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:
CopySample OutputNAME ZPOOL NODE SIZE STATUS FILESYSTEM AGE
pvc-34133838-0d0d-11ea-96e3-42010a800114 zfspv-pool zfspv-node1 4294967296 Ready zfs 4s -
To describe the ZFS volume, use the following command:
CopyDisplay Detailed Information about the ZFS Volumekubectl describe zv pvc-34133838-0d0d-11ea-96e3-42010a800114 -n puls8
CopySample OutputName: 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 nodezfspv-node1
within the specified ZFS pool. The dataset name will match the persistent volume (PV) name. -
Verifying the Volume on the Node - To confirm the dataset creation, log in to the node
zfspv-node1
and execute the following command:CopySample OutputNAME 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