Skip to main content

This section explains the instructions to deploy an application for the OpenEBS Local Persistent Volumes (PV) backed by LVM Storage.

Create the deployment yaml using the PVC backed by LVM storage.

$ cat fio.yaml
apiVersion: v1
kind: Pod
metadata:
name: fio
spec:
restartPolicy: Never
containers:
- name: perfrunner
image: openebs/tests-fio
command: ["/bin/bash"]
args: ["-c", "while true ;do sleep 50; done"]
volumeMounts:
- mountPath: /datadir
name: fio-vol
tty: true
volumes:
- name: fio-vol
persistentVolumeClaim:
claimName: csi-lvmpv

After the deployment of the application, we can go to the node and see that the LVM volume is being used by the application for reading/writing the data and space is consumed from the LVM.

note

Check the provisioned volumes on the node, we need to run pvscan --cache command to update the LVM cache and then we can use lvdisplay and all other LVM commands on the node.

PersistentVolumeClaim Conformance Matrix#

The following matrix shows supported PersistentVolumeClaim parameters for localpv-lvm.

Parameter Values Development Status E2E Coverage Status
AccessMode ReadWriteOnce Supported Yes
ReadWriteMany Not Supported
ReadOnlyMany Not Supported
Storageclass StorageClassName Supported Yes
Capacity Resource Number along with size unit Supported Yes
VolumeMode Block Supported Yes
Test cases available for Filesystem mode
Filesystem Supported
Selectors Equality & Set based selections Supported Pending
VolumeName Available PV name Supported Pending
DataSource - Not Supported Pending

PersistentVolumeClaim Parameters#

AccessMode

LVM-LocalPV supports only ReadWriteOnce access mode i.e. volume can be mounted as read-write by a single node. AccessMode is a required field, if the field is unspecified then it will lead to a creation error. See here for more information about the access modes workflow.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-lvmpv
spec:
accessModes:
- ReadWriteOnce ## Specify ReadWriteOnce(RWO) access modes
storageClassName: openebs-lvm
resources:
requests:
storage: 4Gi

StorageClassName

LVM CSI-Driver supports dynamic provision of volume for the PVCs referred to as LVM storageclass. StorageClassName is a required field, if the field is unspecified then it will lead to provision error. See here for more information about the dynamic provisioning workflow.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-lvmpv
spec:
accessModes:
- ReadWriteOnce
storageClassName: openebs-lvm ## It must be OpenEBS LVM storageclass for provisioning LVM volumes
resources:
requests:
storage: 4Gi

Capacity Resource

Admin/User can specify the desired capacity for LVM volume. CSI-Driver will provision a volume if the underlying volume group has requested capacity available else provisioning volume will be errored. StorageClassName is a required field, if the field is unspecified then it will lead to provisioning errors. See here for more information about the workflows.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-lvmpv
spec:
accessModes:
- ReadWriteOnce
storageClassName: openebs-lvm
resources:
requests:
storage: 4Gi ## Specify required storage for an application

VolumeMode (Optional)

Local PV LVM supports two kinds of volume modes (Defaults to Filesystem mode):

Block (Block mode can be used in a case where the application itself maintains filesystem) Filesystem (Application which requires filesystem as a prerequisite)

note

If unspecified defaults to Filesystem mode. See here for more information about workflows.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-lvmpv
spec:
accessModes:
- ReadWriteOnce
storageClassName: openebs-lvm
volumeMode: Filesystem ## Specifies in which mode volume should be attached to pod
resources:
requests:
storage: 4Gi

Selectors (Optional)

Users can bind any of the retained LVM volumes to the new PersistentVolumeClaim object via the selector field. If the selector and volumeName fields are unspecified then the LVM CSI driver will provision new volume. If the volume selector is specified then request will not reach to local pv driver. This is a use case of pre-provisioned volume. See here for more information about the workflows.

Follow the below steps to specify selector on PersistentVolumeClaim:

  • List the PersistentVolumes(PVs) which has status Released.
$ kubectl get pv -ojsonpath='{range .items[?(@.status.phase=="Released")]}{.metadata.name} {.metadata.labels}{"\n"}'
pvc-8376b776-75f9-4786-8311-f8780adfabdb {"openebs.io/lvm-volume":"reuse"}
note

If labels do not exist for persistent volume then it is required to add labels to PV.

$ kubectl label pv pvc-8376b776-75f9-4786-8311-f8780adfabdb openebs.io/lvm-volume=reuse
  • Remove the claimRef on selected persistentvolumes using patch command. (This will mark PV as Available for binding).
$ kubectl patch pv pvc-8376b776-75f9-4786-8311-f8780adfabdb -p '{"spec":{"claimRef": null}}'
persistentvolume/pvc-8376b776-75f9-4786-8311-f8780adfabdb patched
  • Create PVC with the selector.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-lvmpv
spec:
storageClassName: openebs-lvmpv
## Specify selector matching to available PVs label, K8s will be bound to any of the available PVs matching the specified labels
selector:
matchLabels:
openebs.io/lvm-volume: reuse
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi ## Capacity should be less than or equal to available PV capacities
  • Verify bound status of PV.
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-8376b776-75f9-4786-8311-f8780adfabdb 6Gi RWO Retain Bound default/csi-lvmpv openebs-lvmpv 9h

VolumeName (Optional)

VolumeName can be used to bind PersistentVolumeClaim(PVC) to retained PersistentVolume(PV). When VolumeName is specified K8s will ignore selector field. If volumeName field is specified Kubernetes will try to bind to specified volume(It will help to create claims for pre provisioned volume). If volumeName is unspecified then CSI driver will try to provision new volume. See here for more information about the workflows.

note

Before creating PVC make retained/preprovisioned PersistentVolume Available by removing claimRef on PersistentVolume.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: csi-lvmpv
spec:
storageClassName: openebs-lvmpv
volumeName: pvc-8376b776-75f9-4786-8311-f8780adfabdb ## Name of LVM volume present in Available state
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi ## Capacity should be less than or equal to available PV capacities

Deprovisioning#

To deprovision the volume we can delete the application that is using the volume and then we can go ahead and delete the PV, as part of the deletion of PV this volume will also be deleted from the volume group and data will be freed.

$ kubectl delete -f fio.yaml
pod "fio" deleted
$ kubectl delete -f pvc.yaml
persistentvolumeclaim "csi-lvmpv" deleted

Limitation#

Resize of volumes with snapshot is not supported.

Support#

If you encounter issues or have a question, file a Github issue, or talk to us on the #openebs channel on the Kubernetes Slack server.

See Also#

Was this page helpful? We appreciate your feedback