Chapter 9. Request persistent storage for workspaces
Configure persistent storage for OpenShift Dev Spaces workspaces to preserve project files, editor settings, and installed dependencies across workspace restarts.
9.1. Persistent storage for workspaces Copy linkLink copied to clipboard!
OpenShift Dev Spaces workspaces and workspace data are ephemeral and are lost when the workspace stops.
To preserve the workspace state in persistent storage while the workspace is stopped, request a Kubernetes PersistentVolume (PV). The PV is requested for the Dev Workspace containers in the OpenShift cluster of your organization’s OpenShift Dev Spaces instance.
You can request a PV by using the devfile or a Kubernetes PersistentVolumeClaim (PVC).
An example of a PV is the /projects/ directory of a workspace, which is mounted by default for non-ephemeral workspaces.
Persistent Volumes come at a cost: attaching a persistent volume slows workspace startup.
Starting another, concurrently running workspace with a ReadWriteOnce PV might fail.
9.2. Request persistent storage in a devfile Copy linkLink copied to clipboard!
When a workspace requires its own persistent storage, request a PersistentVolume (PV) in the devfile, and OpenShift Dev Spaces automatically manages the necessary PersistentVolumeClaims.
Prerequisites
- You have not started the workspace.
Procedure
Add a
volumecomponent in the devfile:... components: ... - name: <chosen_volume_name> volume: size: <requested_volume_size>G ...Add a
volumeMountfor the relevantcontainerin the devfile:... components: - name: ... container: ... volumeMounts: - name: <chosen_volume_name_from_previous_step> path: <path_where_to_mount_the_PV> ...For example, when a workspace is started with the following devfile, the
cachePV is provisioned to thegolangcontainer in the/.cachecontainer path:schemaVersion: 2.1.0 metadata: name: mydevfile components: - name: golang container: image: golang memoryLimit: 512Mi mountSources: true command: ['sleep', 'infinity'] volumeMounts: - name: cache path: /.cache - name: cache volume: size: 2Gi
9.3. Request persistent storage in a PVC Copy linkLink copied to clipboard!
Apply a PersistentVolumeClaim (PVC) to provision a PersistentVolume (PV) for your workspaces, so that data persists beyond workspace restarts and can be shared across workspaces.
A PVC is useful in the following cases:
- Not all developers of the project need the PV.
- The PV lifecycle goes beyond the lifecycle of a single workspace.
- The data included in the PV are shared across workspaces.
This also applies to ephemeral workspaces with the controller.devfile.io/storage-type: ephemeral attribute.
Prerequisites
- You have not started the workspace.
-
You have an active
ocsession with administrative permissions to the destination OpenShift cluster. See Getting started with the CLI. -
You have a PVC created in your user project to mount to all
Dev Workspacecontainers.
Procedure
Add the
controller.devfile.io/mount-to-devworkspace: truelabel to the PVC.$ oc label persistentvolumeclaim <PVC_name> \ controller.devfile.io/mount-to-devworkspace=trueOptional: Use the annotations to configure how the PVC is mounted:
Expand Table 9.1. Optional annotations Annotation Description controller.devfile.io/mount-path:The mount path for the PVC.
Defaults to
/tmp/<PVC_name>.controller.devfile.io/read-only:Set to
'true'or'false'to specify whether the PVC is to be mounted as read-only.Defaults to
'false', resulting in the PVC mounted as read/write.For example, to mount a read-only PVC:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: <pvc_name> labels: controller.devfile.io/mount-to-devworkspace: 'true' annotations: controller.devfile.io/mount-path: </example/directory> controller.devfile.io/read-only: 'true' spec: accessModes: - ReadWriteOnce resources: requests: storage: 3Gi storageClassName: <storage_class_name> volumeMode: Filesystemwhere:
</example/directory>- The mounted PV is available at this path in the workspace.
3Gi- Example size value of the requested storage.
<storage_class_name>- The name of the StorageClass required by the claim. Remove this line if you want to use a default StorageClass.