Volume Snapshots
Okteto Volume Snapshots allow you to initialize Persistent Volume Claims (PVCs) with data from a previously created snapshot. This is useful when working with large datasets or when you need to create Development Environments with realistic data from production or staging.
Common use cases:
- Restoring a database (PostgreSQL, MySQL, etc.) with real data for development and testing
- Quickly populating a Development Environment with staging or production data
- Cloning datasets for machine learning models, logs, or images
How Volume Snapshots Work
- Your application uses a Persistent Volume Claim (PVC) to store data (e.g., a PostgreSQL or MySQL database)
- You create a snapshot of this volume, capturing the data at that moment
- When deploying a new Development Environment, you can restore the PVC from the snapshot, ensuring your app starts with the same dataset
This allows you to spin up new environments with fresh, realistic data every time.
Requirements
- Self-Hosted
- SaaS
Follow this guide to enable Volume Snapshots in your cluster.
Make sure your storage class supports snapshots by using a CSI driver that supports volume snapshots for the source persistent volume of your volume snapshots.
If your instance is managed by Okteto, Volume Snapshots are enabled by default.
Important: you need to use the csi-okteto
storage classes for the source persistent volume of your volume snapshots.
Using Volume Snapshots in your Development Environment
Okteto enables developers to initialize persistent volume claims with the contents of a pre-existing volume snapshot. The volume snapshot is created from a persistent volume claim and it can contain database backups, big files, images, a copy of your staging data, etc.
In order to use Volume Snapshots with your Development Environment you need to follow these steps:
- 1. Create the source persistent volume
- 2. Create a volume snapshot of the source persistent volume
- 3. Consume the volume snapshot in a new persistent volume
1. Create the Source Persistent Volume (PVC)
The first step is to ensure your database or application is storing data in a Persistent Volume Claim (PVC). This is the data that you want to be able to clone into your Development Environment. In the example below we use a database, but this could be anything that uses a volume for storage: databases, ML models, images, etc...
If the default storage class of your cluster doesn't support volume snapshots, make sure you set the storage class to one that is compatible when creating your persistent volume. Check the requirements section to learn more about the available storage classes in Okteto.
- Kubernetes
- Compose
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
storageClassName: csi-okteto
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
services:
mysql:
image: mysql
volumes:
- mysql-pvc:/var/lib/mysql
volumes:
mysql-pvc:
driver_opts:
class: csi-okteto
2. Create a Snapshot of the PVC
After creating the source persistent volume, the next step is to create the Volume Snapshot. Volume snapshots are created with the content of the persistent volume at the time of creating the volume snapshot. Further updates on the persistent volume aren't reflected in the volume snapshot content.
This step is independent of whether you created your persistent volume with Kubernetes manifests or a Docker Compose file:
The following manifest creates a volume snapshot from the mysql-pvc
persistent volume claim:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: mysql-snapshot
spec:
volumeSnapshotClassName: okteto-snapshot-class
source:
persistentVolumeClaimName: mysql-pvc
3. Restore a PVC from a Snapshot
Finally, you can use the Volume Snapshot created in the previous step to populate a new persistent volume.
Use the dev.okteto.com/from-snapshot-name
and dev.okteto.com/from-snapshot-namespace
annotations on any persistent volume claim to tell Okteto to initialize your persistent volume claim from an existing volume snapshot, as shown below:
- Kubernetes
- Compose
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
dev.okteto.com/from-snapshot-name: mysql-snapshot
dev.okteto.com/from-snapshot-namespace: staging
name: pvc-from-snapshot
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
services:
mongodb:
image: mysql
volumes:
- data:/var/lib/mysql
volumes:
data:
labels:
dev.okteto.com/from-snapshot-name: mysql-snapshot
dev.okteto.com/from-snapshot-namespace: staging
✅ If the annotation dev.okteto.com/from-snapshot-namespace
is not defined, Okteto will default to the Namespace of the new persistent volume claim.
✅ Use the annotation dev.okteto.com/skip-snapshot-if-same-namespace: "true"
to skip the data cloning operation if the source snapshot and the new persistent volume claim are in the same namespace.
Automating Snapshot Creation in Deployments
You can integrate snapshot creation into your Okteto Manifest so every deployment includes an updated snapshot:
deploy:
- create snapshot
- deploy app