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.
-
Define a new PersistentVolumeClaim:
Create aPersistentVolumeClaim
specification that setsdataSource.kind
toPersistentVolumeClaim
anddataSource.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 -
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
-
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.
-
Create a VolumeSnapshotClass:
Define aVolumeSnapshotClass
with thedriver
field set topxd.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 -
Create a VolumeSnapshot:
Define aVolumeSnapshot
that links to theVolumeSnapshotClass
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 -
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:Then run the command with the full path, for example:kubectl get crd
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.
- If the snapshot does not appear with the
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.
-
Define a new PersistentVolumeClaim:
Create aPersistentVolumeClaim
specification that setsdataSource.kind
toVolumeSnapshot
anddataSource.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 -
Confirm the restored PVC:
Apply thePersistentVolumeClaim
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.