Persistent storageΒΆ
You can ask for persistent storage using the StorageClasses feature with a Persistent Volume Claim (PVC) in Kubernetes. Please keep your requests limited, as the space and performance of a PVC are tightly related.
The default StorageClass in the cluster is named longhorn. PVCs using it are configured to create 3 replicas per volume with Data Locality set to best-effort, meaning replicas will be co-located on the same node whenever possible to improve performance.
Info about how automatic persistent storage backups are done can be found in the Kubernetes backup and monitoring documentation.
Example of using a PVC in Kubernetes, asking for a 2Gi large PVC, and mounting it to /data inside an NGINX container.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: longhorn-volv-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata:
name: volume-test
namespace: default
spec:
containers:
- name: volume-test
image: nginx:stable-alpine
imagePullPolicy: IfNotPresent
volumeMounts:
- name: volv
mountPath: /data
ports:
- containerPort: 80
volumes:
- name: volv
persistentVolumeClaim:
claimName: longhorn-volv-pvc
Longhorn also supports ReadWriteMany containers, but these utilize NFS to provide the filesystem to pods. If your software is unable to use NFS, do not use RWX accessMode.