Adding persistence to your applications
Now, it is time to add storage to your applications; we are going to use the storage classes installed with Longhorn to provide persistence to your applications. In this section, we are going to explore two examples using persistent volumes. In this part of the book, we are going to discuss the persistent volumes and the process of creating storage for a Pod. But first, we need a persistent volume claim definition to provision this storage.
Creating an NGINX pod with a storage volume
To create your NGINX application using a storage volume that uses the Longhorn storage class, follow these steps:
Create
pvc.yaml
:apiVersion: v1 kind: PersistentVolumeClaim metadata: name: longhorn-volv-pvc spec: accessModes: - ReadWriteMany storageClassName: longhorn resources: requests: storage: 2Gi
Apply the
pvc.yaml
YAML file:$ kubectl create -f pvc.yaml
Now, it’s time to create a pod using this PVC that uses the Longhorn storage...