Create Kubernetes Persistent Volume


When running stateful applications on Kubernetes, it is essential to ensure persistence of the underlying volumes. Without persistence, application data is lost whenever a Pod is restarted or updated. Ondat can provide persistent volumes in a Kubernetes-native way while ensuring maximum performance, availability and resilience for the applications you're running, regardless of whether you're on-premise or in the cloud.

Kubernetes provides a Persistent Volume subsystem that abstracts details of how storage is provided from how it is consumed and Ondat can power this subsystem using nearly any underlying storage system.

Ondat provides cloud native storage for Kubernetes used for provisioning Persistent Volumes. Get started in three easy steps:

  1. Establish that you have all the prerequisites for Ondat
  2. Install Ondat to the platform of your choice
  3. Create your first Ondat PersistentVolumeClaim as described below

Ondat Kubernetes Persistent Volume Guide

As a simple first use of Ondat with Kubernetes, following the example below will create a PersistentVolumeClaim (PVC) and schedule a Pod to mount the PersistentVolume (PV) provisioned by the PVC. You can read more about Ondat and Kubernetes best practices in our docs.

Creating a PersistentVolumeClaim

  1. You can find many examples in the Ondat deployment repository
     git clone storageos

    PVC definition:

    The above PVC will dynamically provision a 5GB volume using the fast StorageClass. We will create this StorageClass with some additional parameters to enable encryption.

    StorageClass definition:
  2. Creating a PVC using this StorageClass causes Ondat to provision a PersistentVolume.

    The above PVC has the label set. This label tells Ondat to create a replica for the volume that is created. For the sake of keeping this example simple, we will use the non-replicated PVC from step 1 in the next step.

  3. Move into the examples folder, setup the StorageClass and create a PVC using the PVC definition above.
    $ cd storageos
    $ kubectl create -f ./k8s/examples/000-storageclass.yaml $ kubectl create -f ./k8s/examples/pvc.yaml

    You can view the PVC that you have created with the command below

    $ kubectl get pvc
    my-vol-1 Bound pvc-f8ffa027-e821-11e8-bc0b-0ac77ccc61fa 5Gi RWO fast 1m
  4. Create a pod that mounts the PVC created in step 2.
     $ kubectl create -f ./k8s/examples/debian-pvc.yaml

    The command above creates a Pod that uses the PVC that was created in step 1.

    In the Pod definition above, the volume   v1 references the PVC created in step 2. The volume is mounted in the pod at /mnt. In this example, a debian image is used for the container but any container image with a shell would work.

  5. Confirm that the pod is up and running
     $ kubectl get pods
     d1        1/1     Running   0          1m
  6. Enter a shell inside the container and write some contents to a file
     $ kubectl exec -it d1 -- bash 
     [email protected]:/# echo "Hello World!" > /mnt/helloworld
     [email protected]:/# cat /mnt/helloworld
     Hello World!

    When writing to /mnt inside the container, the same data is written to the underlying StorageOS volume created by the PVC. If you were to kill the pod and start it again on a new node, the helloworld file would still be available.

written by:

Sign up to the Ondat SaaS Platform

Learn how Ondat can help you scale persistent workloads on Kubernetes.