Persisting State with Volumes
Because Kelda can deploy all standard Kubernetes objects, Kubernetes Volumes work out of the box.
To add a volume to your development environment, just modify the Kubernetes YAML in your Workspace configuration to reference the volume.
Persisting State Across Pod Restarts
Persistent Volumes don’t persist state across calls to
The storage device associated with the PVC is released once the PVC is deleted, and Kelda deletes all objects in the namespace when
kelda delete is called.
If you’re interested in persisting state across calls to
kelda delete let us know!
A PVC tells Kubernetes to allocate a Persistent Volume for you. The contents of this volume will be retained even if the pod is deleted. Once a PVC is created, pods can mount it into their filesystem.
This article has a great explanation of how Volumes work in Kubernetes, but in most cases you can just follow one of the examples below.
If PVCs aren’t supported on your Kubernetes cluster…If PVCs aren’t supported on your Kubernetes cluster, you can still use Persistent Volumes. You’ll just need to reference the volume directly from your pod spec.
Example: Persisting Database State
This example Todo application persists the
/data/db directory in the Mongo database across pod restarts. If you force a pod restart with
kubectl delete pod -n <namespace> <pod name>, the database entries will still be present when Mongo boots back up.
All the YAML required to setup the volume is in the Workspace configuration.
The mongodb-pvc.yaml file defines the PVC. This creates a Volume that can be referenced in our Pod.
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: mongo-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi
The Pod references the volume:
volumes: - name: data-volume persistentVolumeClaim: claimName: mongo-pvc
And mounts it into the container:
volumeMounts: - name: data-volume mountPath: /data/db
Resetting Your Volume
If you need to remove the files in your volume, delete and recreate it by running
kelda delete followed by
You can also manually delete files by getting a shell in the container with
kelda ssh, and directly
rming files in the volume.