Skip to main content

Create and use volume snapshot

Follow the instructions on this page to use cloning and snapshot features effectively. These features ensure data availability, quick recovery, and flexibility for various operational scenarios.

  • Snapshot: A snapshot captures the state of your data at a specific moment. It allows you to restore data quickly to that point, minimizing risks of data loss and downtime during failures or disasters.
  • Clone: A clone creates an identical copy of a PVC. This is particularly useful for scenarios such as testing, development, or scaling, as it enables you to work on a duplicate volume without affecting the original.

Clone a PVC

Cloning a PVC lets you create a duplicate volume that mirrors the original, useful for testing or creating backups without affecting live data.

  1. Define a new PersistentVolumeClaim:
    Create a PersistentVolumeClaim specification that sets dataSource.kind to PersistentVolumeClaim and dataSource.name to the name of the PVC to clone. This configuration ensures the new PVC will replicate the original data. For example:

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: pvc-clone
    spec:
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 20Gi
    storageClassName: sc-portworx-fa-direct-access
    dataSource:
    kind: PersistentVolumeClaim
    name: pure-claim-block
  2. Apply the configuration: Save the above configuration in a file clone.yaml and apply on the cluster.

    kubectl apply -f clone.yaml
    persistentvolumeclaim/pvc-clone created
  3. Verify the cloned PVC:
    Run the following command to confirm that the cloned PVC has been created successfully. This step ensures the volume is ready for use.

    kubectl get pvc <pvc-name> -n <pvc-namespace>

Take a Snapshot

Snapshots enable you to quickly restore data to a specific point in time, reducing downtime and preventing data loss.

  1. Create a VolumeSnapshotClass:
    Define a VolumeSnapshotClass with the driver field set to pxd.portworx.com. This class specifies the storage provider for managing snapshots. For example:

    kind: VolumeSnapshotClass
    apiVersion: snapshot.storage.k8s.io/v1
    metadata:
    name: px-fa-direct-access-snapshotclass
    annotations:
    snapshot.storage.kubernetes.io/is-default-class: "true"
    driver: pxd.portworx.com
    deletionPolicy: Delete
  2. Create a VolumeSnapshot:
    Define a VolumeSnapshot that links to the VolumeSnapshotClass and the source PVC. This configuration captures the current state of the PVC. For example:

    kind: VolumeSnapshot
    apiVersion: snapshot.storage.k8s.io/v1
    metadata:
    name: volumesnapshot-of-pure-claim-block
    spec:
    volumeSnapshotClassName: px-fa-direct-access-snapshotclass
    source:
    persistentVolumeClaimName: pure-claim-block
  3. Confirm the snapshot:
    Apply the snapshot configuration and verify its creation using the following command:

    kubectl get volumesnapshot

    Alternatively, check the array UI under Volume Snapshots, where snapshots are managed like other Pure snapshots.

    note
    • If the snapshot does not appear with the kubectl get volumesnapshot command, retrieve the full CRD path using:
      kubectl get crd
      Then run the command with the full path, for example:
      kubectl get volumesnapshots.snapshot.storage.k8s.io
    • Snapshots of unattached volumes will be empty and unattachable. To create an attachable snapshot with a filesystem, attach and detach the volume before taking the snapshot.

Restore a Snapshot

Restoring a snapshot allows you to create a new PVC from a snapshot, which can be useful for recovering data or creating test environments.

  1. Define a new PersistentVolumeClaim:
    Create a PersistentVolumeClaim specification that sets dataSource.kind to VolumeSnapshot and dataSource.name to the snapshot name. This ensures the new PVC is restored from the specified snapshot. For example:

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: pvc-restore
    spec:
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 20Gi
    storageClassName: sc-portworx-fa-direct-access
    dataSource:
    kind: VolumeSnapshot
    name: volumesnapshot-of-pure-claim-block
    apiGroup: snapshot.storage.k8s.io
  2. Confirm the restored PVC:
    Apply the PersistentVolumeClaim configuration and verify its creation using the following command:

    kubectl get pvc <pvc-name> -n <pvc-namespace>

    Alternatively, check the FlashArray UI under volume Details, where the source of the new volume will be listed as the snapshot’s original PVC.