You can dynamically provision a snapshot or create a pre-provisioned volume snapshot of a block volume in a TKG Service cluster. You can also restore an existing snapshot.

Note: You should not create volume snapshot classes and use them to create volume snapshots. Only use a pre-existing volume snapshot class. Pre-existing volume snapshot classes support only the Delete deletionPolicy. Creating volume snapshot classes with the Retain deletionPolicy is not supported.

Create a Dynamically Provisioned Snapshot in a TKG Service Cluster

Dynamically provision a snapshot in a TKG Service cluster.

Procedure

  1. Verify that the StorageClass is present.
    $ kubectl get sc
    NAME                             PROVISIONER              RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
    gc-storage-profile               csi.vsphere.vmware.com   Delete          Immediate              true                   11d
    gc-storage-profile-latebinding   csi.vsphere.vmware.com   Delete          WaitForFirstConsumer   true                   11d
    
  2. Create a PVC using the StorageClass from Step 1.
    Use the following YAML as example.
    $ cat example-pvc.yaml
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: example-raw-block-pvc
    spec:
      volumeMode: Block
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
      storageClassName: gc-storage-profile
    
    $ kubectl apply -f example-pvc.yaml
    $ kubectl get pvc
    NAME                    STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS         AGE
    example-raw-block-pvc   Bound    pvc-4c0c030d-25ac-4520-9a04-7aa9361dfcfc   1Gi        RWO            gc-storage-profile   2m1s
    
  3. Verify that the VolumeSnapshotClass is available.
    $ kubectl get volumesnapshotclass
    NAME                         DRIVER                   DELETIONPOLICY   AGE
    volumesnapshotclass-delete   csi.vsphere.vmware.com   Delete           11d
    
  4. Create a VolumeSnapshot using the VolumeSnapshotClass you obtained in Step 3.
    $cat example-snapshot.yaml
    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshot
    metadata:
      name: example-raw-block-snapshot
    spec:
      volumeSnapshotClassName: volumesnapshotclass-delete
      source:
        persistentVolumeClaimName: example-raw-block-pvc
    
    $ kubectl apply -f example-snapshot.yaml
    $ kubectl get volumesnapshot
    NAME                         READYTOUSE   SOURCEPVC               SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS                SNAPSHOTCONTENT
                                CREATIONTIME   AGE
    example-raw-block-snapshot   true         example-raw-block-pvc                           1Gi           volumesnapshotclass-delete   snapcontent-ae019c16-b07c-4a92-868b-029babd641d3   6s             6s
    
    

Create a Pre-Provisioned Snapshot in a TKG Service Cluster

Create a pre-provisioned volume snapshot of any block volume (PVC) in a TKG Service cluster using a volume snapshot of the same block volume (PVC) from the Supervisor.

Follow these steps to statically create a volume snapshot in a new TKG cluster using the information from the leftover underlying snapshot in Supervisor.

Note: You cannot create volume snapshots directly on a Supervisor.

Prerequisites

  • Be familiar with information about creating Kubernetes snapshots. For details, see the Volume Snapshots page in Kubernetes documentation.
  • Make sure that the volume snapshot satisfies the following conditions:
    • The volume snapshot is present in the same namespace where the source PVC resides.
    • The volume snapshot is present in the same namespace where the TKG cluster resides.

You can also reuse in a new TKG cluster a volume snapshot that is no longer needed by another TKG cluster in same namespace. To do this, change the deletionPolicy of the VolumeSnapshotContent in the original TKG cluster to Retain, and then delete the corresponding VolumeSnapshot as well as VolumeSnapshotContent objects.

Procedure

  1. Note the name of the original VolumeSnapshot object in the Supervisor.
    If you are reusing the volume snapshot from an old TKG cluster, you can also retrieve the Supervisor VolumeSnapshot name from the snapshotHandle of the old VolumeSnapshotContent object in the old TKG cluster.
  2. Create a VolumeSnapshotContent object.
    In the YAML file, specify the value of the following item:
    For snapshotHandle, enter the Supervisor VolumeSnapshot name that you obtained in Step 1.
    Note: Note: If you are reusing a volume snapshot from another TKG cluster, delete the VolumeSnapshot and VolumeSnapshotContent objects from the old TKG cluster, with deletionPolicy set to Retain, before creating a VolumeSnapshotContent in the new TKG cluster.
    Use the following YAML manifest as an example.
    --------
    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshotContent 
    metadata:
     name: static-tkg-block-snapshotcontent 
    spec:
     deletionPolicy: Delete
     driver: csi.vsphere.vmware.com
     source:
      snapshotHandle: "supervisor-block-volumeSnapshot-name" # Enter the VolumeSnapshot name from the Supervisor.
     volumeSnapshotRef:
      name: static-tkg-block-snapshot
      namespace: "supervisor-tkg-namespace" # Enter the namespace of Tanzu Kubernetes Grid Cluster.
    ---------
  3. Create a VolumeSnapshot to match the VolumeSnapshotContent object you created in Step 2.
    ---------
    apiVersion: snapshot.storage.k8s.io/vl
    kind: VolumeSnapshot
    metadata:
     name: static-tkg-block-snapshot 
    spec: 
     source:
      volumeSnapshotContentName: static-tkg-block-snapshotcontent
    ---------
    
  4. Verify that the VolumeSnapshot you created in Step 3 is marked with ReadyToUse as “true”.
    kubecti getvolumesnapshot static-tkg-block-snapshot
    NAME	                   READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT            RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT	              CREATIONTIME AGE
    static-tkg-block-snapshot  true	             static-tkg-biock-snapshotcontent 5Gi	                   static-tkg-block-snapsnotcontent 76m	      22m
    

Restore a Volume Snapshot in a TKG Service Cluster

Restore a volume snapshot that has been already created.

Procedure

  1. Verify that the volume snapshot to restore is available in the TKG cluster.
    $ kubectl get volumesnapshot
    NAME                         READYTOUSE   SOURCEPVC               SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS                SNAPSHOTCONTENT                                    CREATIONTIME   AGE
    example-raw-block-snapshot   true         example-raw-block-pvc                           1Gi           volumesnapshotclass-delete   snapcontent-ae019c16-b07c-4a92-868b-029babd641d3   2m36s          2m36s
    
  2. Create a PVC from the volume snapshot.
    $ cat example-restore.yaml
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: example-raw-block-restore
    spec:
      storageClassName: gc-storage-profile
      dataSource:
        name: example-raw-block-snapshot
        kind: VolumeSnapshot
        apiGroup: snapshot.storage.k8s.io
      volumeMode: Block
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 1Gi
    
    $ kubectl apply -f example-restore.yaml
    $ kubectl get pvc
    NAME                        STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS         AGE
    example-raw-block-pvc       Bound    pvc-4c0c030d-25ac-4520-9a04-7aa9361dfcfc   1Gi        RWO            gc-storage-profile   11m
    example-raw-block-restore   Bound    pvc-96eaab16-9ec1-446a-9392-e86d13c9b2e2   1Gi        RWO            gc-storage-profile   2m8s