Skip to main content

Persistent Volume Claims

Persistent volumes (CSI/PVC) are supported. You request storage via a PersistentVolumeClaim; the preinstalled CSI driver creates the volume automatically and attaches it to the node your pod runs on.

Prerequisites​

The CSI driver and the storage class are preinstalled in every cluster. You do not need to install anything.

Storage class​

kubectl get storageclass
PropertyValue
Namecloudstack-custom (default class)
AccessReadWriteOnce – the volume is attached to one node at a time
ProvisioningWaitForFirstConsumer – the volume is created as soon as the first pod uses it
Expansionsupported
When the PVC is deletedThe volume and its data are deleted (Delete)
Still open

We will add size limits per volume once the values are finalised. [DS/Produkt liefert]

1. Create a PVC​

Create a file pvc.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: daten
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi

If you do not specify storageClassName, the default class cloudstack-custom applies.

kubectl apply -f pvc.yaml

2. Use the PVC in an application​

apiVersion: apps/v1
kind: Deployment
metadata:
name: datenbank
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: datenbank
template:
metadata:
labels:
app: datenbank
spec:
containers:
- name: postgres
image: postgres:16
env:
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: daten
volumes:
- name: daten
persistentVolumeClaim:
claimName: daten

Because a volume is attached to only one node at a time, use the Recreate strategy for deployments with a PVC. For multiple replicas with their own volume each, use a StatefulSet with volumeClaimTemplates.

3. Check the status​

kubectl get pvc
NAME    STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS        AGE
daten Bound pvc-1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d 20Gi RWO cloudstack-custom 2m

The status Pending is normal as long as no pod uses the PVC yet.

Expand a volume​

Increase the requested size in the PVC:

kubectl patch pvc daten -p '{"spec":{"resources":{"requests":{"storage":"40Gi"}}}}'

Create a snapshot​

The VolumeSnapshotClass cloudstack-snapshot is preinstalled for snapshots:

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: daten-snapshot
spec:
volumeSnapshotClassName: cloudstack-snapshot
source:
persistentVolumeClaimName: daten
kubectl get volumesnapshot

Create a new PVC from the snapshot via dataSource:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: daten-wiederhergestellt
spec:
accessModes:
- ReadWriteOnce
dataSource:
name: daten-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
resources:
requests:
storage: 20Gi
Warnung

Snapshots are deleted together with the VolumeSnapshot object – and with the cluster. They do not replace a backup outside the cluster, for example in S3 Object Storage.

Notes​

  • If you delete a PVC, the volume is deleted with all its data.
  • helm uninstall leaves PVCs created from volumeClaimTemplates in place; remove them yourself if required.
  • If a pod moves to another node, the CSI driver reattaches the volume automatically.