Skip to main content
Version: 1.4

Volume Snapshots

Volume snapshots allows you to initialize persistent volume claims with the contents of a preexisting volume snapshot. Use volume snapshots when working with large datasets or if you want to create development environments with real data coming from your production or staging environments.

Requirements

To use the Volume Snapshots feature, you must install a CSI driver that supports snapshots and create the corresponding VolumeSnapshotClass.

Installing the CSI Driver

Volume Snapshots is compatible with any CSI-compliant driver, such as:

Note: As of February 2021, if you're using the Amazon EBS CSI driver, you'll need to install the alpha version to enable Volume Snapshots. More information is available on their github repository.

We recommend you follow your vendor's installation instructions to learn more about this topic.

Create a VolumeSnapshotClass

Create a VolumeSnapshotClass in your cluster to determine the CSI driver and deletionPolicy for your VolumeSnapshots.

The following manifest is an example of a VolumeSnapshotClass:

# okteto-snapshot-class.yaml
apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshotClass
metadata:
name: okteto-snapshot-class
driver: ebs.csi.aws.com
deletionPolicy: Delete

To create the VolumeSnapshotClass run the following command after creating the file.

kubectl apply -f okteto-snapshot-class.yaml

Create a StorageClass (optional)

Optionally, you can also create a storage class. This storage class will be used by Okteto when creating the volumes.

# okteto-snapshot-sc.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: okteto-snapshot-sc
provisioner: ebs.csi.aws.com
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

To create the StorageClass run the following command after creating the file.

kubectl apply -f okteto-snapshot-sc.yaml

Enabling Volume Snapshots

To enable Volume Snapshots on your Okteto instance, update your config.yaml file with the following values, and run a helm upgrade to apply the new configuration.

More information on the different configuration settings is available here.

volumeSnapshots:
enabled: true
driver: ebs.csi.aws.com
class: okteto-snapshot-class
storageClass: okteto-snapshot-sc

By default, all users in your cluster will be able to use any of the available snapshots as a data source for their development environments. You can limit this via the enableNamespaceAccessValidation key in the volumeSnapshots section of the configuration, value of true will enable the validation.

Using Storage Snapshots in your Development Environment

If your data source is not on Kubernetes, you can instead create a storage snapshot directly from your cloud provider (consult your cloud provider's documentation on how to generate a volume snapshot).

Use the dev.okteto.com/from-snapshot-id annotation on any persistent volume claim to tell Okteto to initialize your persistent volume claim from a storage snapshot created in your cloud provider, as shown below:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
dev.okteto.com/from-snapshot-id: snapshot-8dc4bb4c
name: pvc-from-snapshot
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi

As part of the creation of the persistent volume claim, Okteto will import the specified snapshot into your cluster using a VolumeSnapshotContent and will set the source of your persistent volume claim to this VolumeSnapshotContent, ready to be used by your development environment.

By default, anyone can use any of your cloud provider's snapshot ID as a data source. You can disable this by changing the configuration allowIDAnnotation to false in the volumeSnapshots section of the configuration.