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.
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 imagemy-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 to10Gi
)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 toReadWriteOnce
)readOnly
: if the persistent volume claim should get mounted in read only mode. (Defaults tofalse
)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
andmy-image/backend
with pods that mount the persistent volume claim calledmy-pvc
- DevSpace will sync the local files into the persisted folder
/app
of the replaced pod with imagemy-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
persistPaths
required object[] 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.
path
required string volumePath
required string
VolumePath is the sub path on the volume that is mounted as persistent volume for this path
volumePath
required string readOnly
required boolean false
ReadOnly will make the persistent path read only to the user
readOnly
required boolean false skipPopulate
required boolean false
SkipPopulate will not create an init container to copy over the existing contents if true
skipPopulate
required boolean false initContainer
required
InitContainer holds additional options for the persistent path init container
initContainer
required persistenceOptions
required
PersistenceOptions are additional options for persisting paths within this pod
persistenceOptions
required size
required string
Size is the size of the created persistent volume in Kubernetes size notation like 5Gi
size
required string storageClassName
required string
StorageClassName is the storage type DevSpace should use for this persistent volume
storageClassName
required string accessModes
required string[]
AccessModes are the access modes DevSpace should use for the persistent volume
accessModes
required string[] readOnly
required boolean false
ReadOnly specifies if the volume should be read only
readOnly
required boolean false 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.
name
required string