Skip to main content
Version: 6.x (Latest)

Persist Paths In Dev Containers

DevSpace offers you the ability to easily persist certain folders in an exchanged pod through a persistent volume claim. This might be useful if you have to sync large amounts of files that are needed in multiple containers or the replaced pod might get rescheduled or killed often.

Cleanup of Persistent Volume Claims

If DevSpace creates the persistent volume claim, it will also get cleaned up on a devspace reset pods or if config changes in the replacePods section are detected.

Persist Paths In Dev Container

The persistPaths option expects an array of paths that should get persisted on the replaced pod.

Example: Persist the folders

dev:
my-dev:
imageSelector: my-app/dev
persistPaths:
- path: /app
# Optional path on the persistent volume to mount
# volumePath: my-volume/app
# Optional name of the container to persist this path
# containerName: my-container

Explanation:

  • The imageSelector would select the pod with image my-app/dev.
  • DevSpace would create a new persistent volume claim for the pod if the pod was not yet replaced
  • DevSpace would replace the pod with a pod which has a volume mount for the path /app that references the created persistent volume claim

Persistence Options

persistenceOptions is an object that defines additional options for persistPaths. You can configure the following options:

  • size: the size of the persistent volume to request. (Defaults to 10Gi)
  • storageClassName: the storage class name to use for the persistent volume claim. (Defaults to empty)
  • accessModes: the access modes to use for the persistent volume claim. (Defaults to ReadWriteOnce)
  • readOnly: if the persistent volume claim should get mounted in read only mode. (Defaults to false)
  • name: the name of the persistent volume claim to use or create. (Defaults to name of the replaced pod)

Example: Share a single persistent volume across two pods

dev:
frontend:
imageSelector: my-image/frontend
sync:
- path: .:/app
persistPaths:
- path: /app
volumePath: app
persistenceOptions:
name: my-pvc

backend:
imageSelector: my-image/backend
persistPaths:
- path: /backend
volumePath: app
persistenceOptions:
name: my-pvc
readOnly: true

Explanation:

  • DevSpace will create a persistent volume claim my-pvc if it does not exist
  • DevSpace will replace the pods with image my-image/frontend and my-image/backend with pods that mount the persistent volume claim called my-pvc
  • DevSpace will sync the local files into the persisted folder /app of the replaced pod with image my-image/frontend. Since the replaced pods share a common persistent volume claim, also the backend container will get the updated files.

Config Reference

persistPaths required object[]

PersistPaths allows you to persist certain paths within this container with a persistent volume claim

path required string

Path is the container path that should get persisted. By default, DevSpace will create an init container that will copy over the contents of this folder from the existing image.

volumePath required string

VolumePath is the sub path on the volume that is mounted as persistent volume for this path

readOnly required boolean false

ReadOnly will make the persistent path read only to the user

skipPopulate required boolean false

SkipPopulate will not create an init container to copy over the existing contents if true

initContainer required

InitContainer holds additional options for the persistent path init container

resources required

Resources are the resources used by the persistent path init container

requests required <request_name>:string

Requests are the requests part of the resources

limits required <limit_name>:string

Limits are the limits part of the resources

persistenceOptions required

PersistenceOptions are additional options for persisting paths within this pod

size required string

Size is the size of the created persistent volume in Kubernetes size notation like 5Gi

storageClassName required string

StorageClassName is the storage type DevSpace should use for this persistent volume

accessModes required string[]

AccessModes are the access modes DevSpace should use for the persistent volume

readOnly required boolean false

ReadOnly specifies if the volume should be read only

name required string

Name is the name of the PVC that should be created. If a PVC with that name already exists, DevSpace will use that PVC instead of creating one.