Skip to main content

Volume Snapshots

Use volume snapshots to enable your users to initialize persistent volume claims with the contents of a preexisting storage 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 Enterprise 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

Using Volume Snapshots in your Development Environment

Creating a Volume Snapshot

Volume Snapshots allow developers to initialize persistent volume claims with the contents of any preexisting storage snapshot. The snapshot can contain database backups, big files, images, a copy of your staging data, etc.

apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
name: mysql-snapshot
spec:
volumeSnapshotClassName: okteto-snapshot-class
source:
persistentVolumeClaimName: mysql-snapshot

Consuming a Volume Snapshot created in Kubernetes

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 a VolumeSnapshot Kubernetes object, as shown below:

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

If the annotation dev.okteto.com/from-snapshot-namespace is not defined, Okteto will default to the namespace of the new persistent volume claim.

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.