Volume snapshots
This feature is only available for the following:
- Host Nodes
- Private Nodes
This feature is currently in Beta. See vCluster Lifecycle Policy for more information.
vCluster snapshots enable you to create volume snapshots for PersistentVolumeClaims that are provisioned by CSI drivers. This allows you to protect not only your virtual cluster resources and config, but also your application data.
See how volume snapshots are created if you would like to learn more about volume snapshots and how vCluster creates them.
Volume snapshots can be created only for PVCs that are provisioned by CSI drivers with Volume Snapshots support.
Setup​
In order to create volume snapshots, several installation and configuration steps have to be done in your host or virtual cluster.
Host nodes​
The following setup has to be done in the host cluster:
- Install the Kubernetes CSI snapshotter and VolumeSnapshot, VolumeSnapshotContent and VolumeSnapshotClass CRDs. You can find further instructions in the upstream repo.
- Install a CSI driver that supports volume snapshots, and storage classes for that CSI driver.
- Configure the default VolumeSnapshotClass for each CSI driver in the host cluster. See Kubernetes Volume Snapshot Classes docs for more details.
Private nodes​
Create virtual cluster with deploy.volumeSnapshotController.enabled config set to true. With this config, vCluster installs the common snapshot-controller, and VolumeSnapshot, VolumeSnapshotContent and VolumeSnapshotClass CRDs in your virtual cluster.
The following setup has to be done in the virtual cluster:
- Install a CSI driver that supports volume snapshots, and storage classes for that CSI driver.
- Configure the default VolumeSnapshotClass for each CSI driver in the host cluster. See Kubernetes Volume Snapshot Classes docs for more details.
Use non-default VolumeSnapshotClasses​
There can be scenarios where you need to use different VolumeSnapshotClasses for different PersistentVolumeClaims that have been provisioned by the same CSI driver. In cases like this, you cannot use the default VolumeSnapshotClass for all PersistentVolumeClaims. For example, this can happen when you use multiple StorageClasses from the same CSI driver, so you might be required to use multiple VolumeSnapshotClasses as well.
To use a non-default VolumeSnapshotClass for some PersistentVolumeClaim, label that PersistentVolumeClaim with vcluster.loft.sh/csi-volumesnapshot-class label, where the label value is the name of the VolumeSnapshotClass that you want to use. For example:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
labels:
vcluster.loft.sh/csi-volumesnapshot-class: my-special-snap-class
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Create snapshot with volumes​
You can create a vCluster snapshot, with volume snapshots included, by using the --include-volumes param. vCluster CLI creates a snapshot request in the host cluster, which is then processed in the background by the vCluster snapshot controller, which will create volume snapshots.
Here is an example:
vcluster snapshot create myvcluster "container:///data/my-snapshot.tar.gz" --include-volumes
13:52:09 info Beginning snapshot creation... You can check the snapshot creation progress with the following command: vcluster snapshot get myvcluster "container:///data/my-snapshot.tar.gz"'
You can check the snapshot creation progress with the following command:
vcluster snapshot get myvcluster "container:///data/my-snapshot.tar.gz"
SNAPSHOT | STATUS | AGE
---------------------------------------+-------------------------+------
container:///data/my-snapshot.tar.gz | CreatingVolumeSnapshots | 28s
Limitations​
When taking volume snapshots, there are limitations:
- Volume snapshots cannot be created for PVCs that are not provisioned by CSI drivers with Volume Snapshots support.
- Volume snapshots cannot be created for PVCs that are provisioned by CSI drivers that don't support Volume Snapshots.
- When using host nodes:
- Currently volume snapshots are created only for PersistentVolumeClaims that are synced to the vCluster host namespace. This means that, when the Namespace sync is enabled, volume snapshots are not created for the PersistentVolumeClaims that are synced to namespaces different than the vCluster host namespace.
- When using private nodes:
- vCluster has to be deployed with
deploy.volumeSnapshotController.enabledconfig set totrue. - CSI driver that supports volume snapshots has to be installed in the virtual cluster.
- The default VolumeSnapshotClass has to be configured for each CSI driver in the virtual cluster. See Kubernetes Volume Snapshot Classes docs for more details.
- vCluster has to be deployed with
- Volume snapshots are currently not supported for vCluster standalone.
Troubleshoot issues​
If not all your Volumes are able to be backed up or restored, there are several different outcomes that can happen during restore, depending on the reason. These states are likely to change over coming releases.
| Case | PVC Exists | PVC State | Restored by |
|---|---|---|---|
| Volume provisioner is valid CSI driver that supports snapshots | Yes | Bound | Snapshot Controller |
| Volume provisioner is valid CSI driver that does not support snapshots | No | N/A | Snapshot Controller |
| Volume provisioner is not valid CSI driver | Yes | Varying (a) | ETCD |
| Volume has other error, such as missing VolumeSnapshot or Storage Class | No | N/A | Snapshot Controller |
| Volume and provisioner are valid, but PVC already exists in cluster | Untouched | Untouched (b) | Skipped |
a) This depends on the provisioner. In some cases it will end up pending, in others it may be restored. For example if everything needed exists locally.
b) If a PVC already exists in the cluster, the snapshot feature will not overwrite it. You will need to delete it and run the restore again.