vSphere Container Storage Plug-in supports the volume snapshot and restore capabilities. You can use a snapshot to provision a new volume, pre-populated with the snapshot data. You can also restore the existing volume to a previous state represented by the snapshot.
Volume Snapshot and Restore Requirements
Your environment must meet general requirements that apply to vSphere Container Storage Plug-in. For more information, see Preparing for Installation of vSphere Container Storage Plug-in.
In addition, follow these requirements to use the volume snapshot and restore feature with vSphere Container Storage Plug-in:
CSI upstream external-snapshotter/snapshot-controller version 5.0.1 or higher.
vSphere version 7.0 Update 3 or higher.
The minimum version applies to both vCenter Server and ESXi.
Volume Snapshot CRD v1 is supported.
Volume Snapshot CRD v1beta1 and v1alpha1 are not supported.
Enable Volume Snapshot and Restore
Enable the volume snapshot and restore capabilities for vSphere Container Storage Plug-in.
Procedure
Using Volume Snapshot and Restore
After you enable the volume snapshot and restore capabilities for vSphere Container Storage Plug-in, you can create a snapshot dynamically or statically. You can also create a PVC from a volume snapshot.
To use the volume snapshot and restore feature, see the following example. In the example, the optional parameters are commented.
kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: example-vanilla-rwo-filesystem-sc annotations: storageclass.kubernetes.io/is-default-class: "true" # Optional provisioner: csi.vsphere.vmware.com allowVolumeExpansion: true # Optional: only applicable to vSphere 7.0U1 and above parameters: csi.storage.k8s.io/fstype: "ext4" # datastoreurl: "ds:///vmfs/volumes/vsan:52cdfa80721ff516-ea1e993113acfc77/" # Optional Parameter # storagepolicyname: "vSAN Default Storage Policy" # Optional Parameter
Volume Snapshot and Restore Limitations
Before you start using the volume snapshot and restore feature, consider the following limitations:
- When you create a PVC from a VolumeSnapshot, it should reside on the same datastore as the original VolumeSnapshot. Otherwise, the provisioning of that PVC will fail with the following error:
failed to provision volume with StorageClass "vmfs12": rpc error: code = Internal desc = failed to create volume. Error: failed to get the compatible datastore for create volume from snapshot 0a3ce642-2c19-4d50-9534-7889b2a6db52+fc01aaa4-29d8-4a68-90ba-b1d53bb0657d with error: failed to find datastore with URL "ds:///vmfs/volumes/62fd07ba-4b18326e-137a-1c34da62fa18/" from the input datastore list, [Datastore:datastore- 33 Datastore:datastore-34]
Note: The datastore for the target PVC that you create from the VolumeSnapshot is determined by the StorageClass in the PVC definition. Make sure that the StorageClass of the target PVC and the StorageClass of the original source PVC point to the same datastore, which is the datastore of the source PVC. This rule also applies to the topology requirements in the StorageClass definitions. The requirements must also point to the same common datastore. Any conflicting topology requirements result in the same error as shown above. - You cannot delete or expand a volume that contains associated snapshots. Delete all snapshots to expand or delete a volume.
- When you create a volume from a snapshot, ensure that the size of the volume matches the size of the snapshot.
Create Dynamically Provisioned Snapshots
You can dynamically provision a snapshot for vSphere Container Storage Plug-in.
Procedure
Create Pre-Provisioned Snapshots
Pre-provision a snapshot for the vSphere Container Storage Plug-in.
Prerequisites
- Ensure that an FCD snapshot is available in your vSphere environment.
Note:
- Pre-provisioned CSI snapshots are supported for CNS/FCD snapshots created using Kubernetes
VolumeSnapshot
APIs for vSphere 7.0 Update 3 and later. - Pre-provisioned CSI snapshots are not supported for FCD snapshots created using FCD APIs directly.
- Pre-provisioned CSI snapshots are supported for CNS/FCD snapshots created using Kubernetes
- Construct the snapshot handle based on the combination of FCD Volume ID and FCD Snapshot ID of the snapshot. For example, if the FCD Volume ID and FCD Snapshot ID for a FCD snapshot are
4ef058e4-d941-447d-a427-438440b7d306
and766f7158-b394-4cc1-891b-4667df0822fa
, the snapshot handle constructed is4ef058e4-d941-447d-a427-438440b7d306+766f7158-b394-4cc1-891b-4667df0822fa
. - Update the
spec.source.snapshotHandle
field in theVolumeSnapshotContent
object of the example-static-snapshot.yaml with the snapshot handle constructed in the above example.
Procedure
- ♦ Create a pre-provisioned volume snapshot.
$ kubectl apply -f example-static-snapshot.yaml $ kubectl get volumesnapshot static-vanilla-rwo-filesystem-snapshot NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE static-vanilla-rwo-filesystem-snapshot true static-vanilla-rwo-filesystem-snapshotcontent 5Gi static-vanilla-rwo-filesystem-snapshotcontent 76m 22m
Restore Volume Snapshots
You can restore a volume snapshot that is already created with vSphere Container Storage Plug-in.
Procedure
Configure Maximum Number of Snapshots per Volume
Configure the maximum number of snapshots per volume for the vSphere Container Storage Plug-in.
Parameter | Description |
---|---|
global-max-snapshots-per-block-volume |
Global configuration parameter that applies to volumes on all kinds of datastores. By default, it is set to three. |
granular-max-snapshots-per-block-volume-vsan |
Granular configuration parameter on vSAN datastore only. It overrides the global constraint if set, while it falls back to the global constraint if unset. A maximum value of 32 can be set under vSAN ESA setup. |
granular-max-snapshots-per-block-volume-vvol |
Granular configuration parameter on Virtual Volumes datastore only. It overrides the global constraint if set. It falls back to the global constraint if unset. |
Prerequisites
- For a better performance, use two to three snapshots per virtual disk. For more information, see Best practices for using VMware snapshots in the vSphere environment.
- Ensure that the maximum number of snapshots per volume is configurable, and its default is set to three.
- The best practice guideline applies only to virtual disks on VMFS and NFS datastores while not to those on Virtual Volumes and vSAN datastores.
- Granular configuration parameters are introduced apart from the global configuration parameter.