OpenEBS Local PV Device User Guide
This guide will help you to set up and use OpenEBS Local Persistent Volumes backed by Block Devices.
OpenEBS Dynamic Local PV provisioner can create Kubernetes Local Persistent Volumes using block devices available on the node to persist data, hereafter referred to as OpenEBS Local PV Device volumes.
OpenEBS Local PV Device volumes have the following advantages compared to native Kubernetes Local Persistent Volumes.
- Dynamic Volume provisioner as opposed to a Static Provisioner.
- Better management of the Block Devices used for creating Local PVs by OpenEBS NDM. NDM provides capabilities like discovering Block Device properties, setting up Device Filters, metrics collection and ability to detect if the Block Devices have moved across nodes.
OpenEBS Local PV uses volume topology aware pod scheduling enhancements introduced by Kubernetes Local Volumes
QUICKSTART
OpenEBS Local PV Device volumes will be created using the Block Devices available on the node. You can customize which block devices can be used for creating Local PVs by configuring NDM parameters and/or by creating new StorageClass.
If you have OpenEBS already installed, you can create an example pod that persists data to OpenEBS Local PV Device with following kubectl commands.
Verify using below kubectl commands that example pod is running and is using a OpenEBS Local PV Device.
For a more detailed walkthrough of the setup, follow along the rest of this document.
#
Minimum Versions- Kubernetes 1.12 or higher is required
- OpenEBS 1.0 or higher is required.
air-gapped environment
If you are running your Kubernetes cluster in an air-gapped environment, make sure the following container images are available in your local repository.
- openebs/localpv-provisioner
- openebs/linux-utils
- openebs/node-disk-manager
- openebs/node-disk-operator
#
PrerequisitesFor provisioning Local PV using the block devices, the Kubernetes nodes should have block devices attached to the nodes. The block devices can optionally be formatted and mounted.
The block devices can be any of the following:
- SSD, NVMe or Hard Disk attached to a Kubernetes node (Bare metal server)
- Cloud Provider Disks like EBS or GPD attached to a Kubernetes node (Cloud instances. GKE or EKS)
- Virtual Disks like a vSAN volume or VMDK disk attached to a Kubernetes node (Virtual Machine)
#
Install#
Customize NDM and InstallYou can skip this section if you have already installed OpenEBS.
OpenEBS Dynamic Local Provisioner uses the Block Devices discovered by NDM to create Local PVs. NDM offers some configurable parameters that can be applied during the OpenEBS Installation. Some key configurable parameters available for NDM are:
Prepare to install OpenEBS by providing custom values for configurable parameters.
The location of the OpenEBS Dynamic Local PV provisioner container image.
The location of the OpenEBS NDM DaemonSet container image. NDM DaemonSet helps with discovering block devices attached to a node and creating Block Device Resources.
The location of the OpenEBS NDM Operator container image. NDM Operator helps with allocating Block Devices to Block Device Claims raised by OpenEBS Dynamic Local PV Provisioner.
The location of the Provisioner Helper container image. OpenEBS Dynamic Local Provisioner create a Provisioner Helper pod to clean up the data from the block device after the PV has been deleted.
Specify the list of block devices for which BlockDevice CRs must be created. A comma separated values of path regular expressions can be specified.
Specify the list of block devices for which BlockDevice CRs must not be created. A comma separated values of path regular expressions can be specified.
You can proceed to install OpenEBS either using kubectl or helm using the steps below.
Install using kubectl
If you would like to change the default values for any of the configurable parameters mentioned in the previous step, download the
openebs-operator.yaml
and make the necessary changes before applying.note
If you would like to use only Local PV (hostpath and device), you can install a lite version of OpenEBS using the following command.
kubectl apply -f https://openebs.github.io/charts/openebs-operator-lite.yaml kubectl apply -f https://openebs.github.io/charts/openebs-lite-sc.yaml
Install using OpenEBS helm charts
If you would like to change the default values for any of the configurable parameters mentioned in the previous step, specify each parameter using the
--set key=value[,key=value]
argument tohelm install
.
#
(Optional) Block Device TaggingYou can reserve block devices in the cluster that you would like the OpenEBS Dynamic Local Provisioner to pick up some specific block devices available on the node. You can use the NDM Block Device tagging feature to reserve the devices. For example, if you would like Local SSDs on your cluster for running Mongo stateful application. You can tag a few devices in the cluster with a tag named mongo
.
#
Create StorageClassYou can skip this section if you would like to use default OpenEBS Local PV Device StorageClass created by OpenEBS.
The default Storage Class is called openebs-device
. If the block devices are not formatted, the devices will be formatted with ext4
.
To create your own StorageClass to customize how Local PV with devices are created. For instance, if you would like to run MongoDB stateful applications with Local PV device, you would want to set the default filesystem as
xfs
and/or also dedicate some devices on node that you want to use for Local PV. Save the following StorageClass definition aslocal-device-sc.yaml
note
The
volumeBindingMode
MUST ALWAYS be set toWaitForFirstConsumer
.volumeBindingMode: WaitForFirstConsumer
instructs Kubernetes to initiate the creation of PV only after Pod using PVC is scheduled to the node.note
The
FSType
will take effect only if the underlying block device is not formatted. For instance if the block device is formatted with "Ext4", specifying "XFS" in the storage class will not clear Ext4 and format with XFS. If the block devices are already formatted, you can clear the filesystem information usingwipefs -f -a <device-path>
. After the filesystem has been cleared, NDM pod on the node needs to be restarted to update the Block Device.Edit
local-device-sc.yaml
and update with your desired values for:metadata.name
cas.openebs.io/config.FSType
cas.openebs.io/config.BlockDeviceTag
note
Block Device Tag support for Local Volumes was introduced in OpenEBS 1.9.
When specifying the value for BlockDeviceTag, you must already have Block Devices on the nodes labelled with the tag. See Block Device Tagging
Create OpenEBS Local PV Device Storage Class.
Verify that the StorageClass is successfully created.
#
Create a PersistentVolumeClaimThe next step is to create a PersistentVolumeClaim. Pods will use PersistentVolumeClaims to request Device backed Local PV from OpenEBS Dynamic Local PV provisioner.
Here is the configuration file for the PersistentVolumeClaim. Save the following PersistentVolumeClaim definition as
local-device-pvc.yaml
Create the PersistentVolumeClaim
Look at the PersistentVolumeClaim:
The output shows that the
STATUS
isPending
. This means PVC has not yet been used by an application pod. The next step is to create a Pod that uses your PersistentVolumeClaim as a volume.
#
Using Raw Block VolumeBy default, Local PV volume will be provisioned with volumeMode as filesystem. If you would like to use it as Raw Block Volume, specify spec.volumeMode
as Block
in the Persistent Volume Claim spec. Here is the configuration file for the PersistentVolumeClaim with Raw Block Volume Support.
note
Raw Block Volume support was introduced for OpenEBS Local PV OpenEBS 1.5.
#
Create Pod to consume OpenEBS Local PV backed by Block DeviceHere is the configuration file for the Pod that uses Local PV. Save the following Pod definition to
local-device-pod.yaml
.note
As the Local PV storage classes use
waitForFirstConsumer
, do not usenodeName
in the Pod spec to specify node affinity. IfnodeName
is used in the Pod spec, then PVC will remain inpending
state. For more details refer https://github.com/openebs/openebs/issues/2915.Create the Pod:
Verify that the container in the Pod is running;
Verify that the container is using the Local PV Device
The output shows that the Pod is running on
Node: gke-user-helm-default-pool-3a63aff5-1tmf
and using the persistent volume provided bylocal-describe-pvc
.Look at the PersistentVolumeClaim again to see the details about the dynamically provisioned Local PersistentVolume
The output shows that the
STATUS
isBound
. A new Persistent Volumepvc-79d25095-eb1f-4028-9843-7824cb82f07f
has been created.Look at the PersistentVolume details to see where the data is stored. Replace the PVC name with the one that was displayed in the previous step.
The output shows that the PV was provisioned in response to PVC request
spec.claimRef.name: local-device-pvc
.
note
A few important characteristics of a OpenEBS Local PV can be seen from the above output:
spec.nodeAffinity
specifies the Kubernetes node where the Pod using the local volume is scheduled.spec.local.path
specifies the path of the block device associated with this PV.
OpenEBS Dynamic Local Provisioner would have created a BlockDeviceClaim to get a BlockDevice from NDM. The BlockDeviceClaim will be having the same name as the PV name. Look at the BlockDeviceClaim details to see which Block Device is being used. Replace the PVC Name in the below command with the PVC name that was displayed in the previous step.
The output shows that the
PHASE
isBound
, and provides the name of the Block Deviceblockdevice-d1ef1e1b9dccf224e000c6f2e908c5f2
Look at the BlockDevice details to see where the data is stored. Replace the BDC name with the one that was displayed in the previous step.
The output shows that the BD is on the node
spec.nodeAttributes.nodeName: gke-user-helm-default-pool-92abeacf-89nd
.
note
A few important details from the above Block Device are:
spec.filesystem
indicates if the BlockDevice has been formatted and the path where it has been mounted.- If the block device is pre-formatted as in the above case, the PV will be created with path as
spec.filesystem.mountPoint
. - If the block device is not formatted, it will be formatted with the filesystem specified in the PVC and StorageClass. Default is
ext4
.
- If the block device is pre-formatted as in the above case, the PV will be created with path as
#
CleanupDelete the Pod, the PersistentVolumeClaim and StorageClass that you might have created.
Verify that the PV that was dynamically created is also deleted.
#
Backup and RestoreOpenEBS Local Volumes can be backed up and restored along with the application using Velero.
note
The following steps assume that you already have Velero with Restic integration is configured. If not, please follow the Velero Documentation to proceed with install and setup of Velero. If you encounter any issues or have questions, talk to us on the #openebs channel on the Kubernetes Slack server.
#
BackupThe following steps will help you to prepare and backup the data from the volume created for the example pod (hello-local-device-pod
), with the volume mount (local-storage
).
Prepare the application pod for backup. Velero uses Kubernetes labels to select the pods that need to be backed up. Velero uses annotation on the pods to determine which volumes need to be backed up. For the example pod launched in this guide, you can inform velero to backup by specifying the following label and annotation.
Create a Backup using velero.
Verify that backup is successful.
On successful completion of the backup, the output of the backup describe command will show the following:
#
RestoreInstall and Setup Velero, with the same provider where backups were saved. Verify that backups are accessible.
The output of should display the backups that were taken successfully.
Restore the application.
note
Local PVs are created with node affinity. As the node names will change when a new cluster is created, create the required PVC(s) prior to proceeding with restore.
Replace the path to the PVC yaml in the below commands, with the PVC that you have created.
Verify that application is restored.
Depending on the data, it may take a while to initialize the volume. On successful restore, the output of the above command should show:
Verify that data has been restored. The application pod used in this example, write periodic messages (greetings) to the volume.
The output will show that backed up data as well as new greetings that started appearing after application pod was restored.
#
TroubleshootingReview the logs of the OpenEBS Local PV provisioner. OpenEBS Dynamic Local Provisioner logs can be fetched using.
#
SupportIf you encounter issues or have a question, file an Github issue, or talk to us on the #openebs channel on the Kubernetes Slack server.