Hello all, how to take snapshot of pv and restore it to new volume. Appreciate y . . .

Vinay Katukam:
Hello all, how to take snapshot of pv and restore it to new volume.
Appreciate your help…

Vinay Katukam:
Can anyone guide me on this…

Rocky:
is it part of the CKA syllabus to take snapshot of PV.

Mohamed Ayman:
Hi @Vinay Katukam,
To create a snapshot of a volume, call kubectl create -f your_snapshot_file.yaml and specify the desired PVC. Here’s an example of a YAML file that defines a snapshot:

apiVersion: <http://snapshot.storage.k8s.io/v1beta1|snapshot.storage.k8s.io/v1beta1>
kind: VolumeSnapshot
metadata:
  name: csi-do-test-snapshot
spec:
  source:
    persistentVolumeClaimName: csi-do-test-pvc

To restore from a given snapshot, you need to create a new PVC that refers to the snapshot by calling kubectl create -f your_restore_file.yaml. Here’s an example of a YAML file that restores from a snapshot and creates a new PVC for use in the cluster:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-do-test-pvc-restore
spec:
  dataSource:
    name: csi-do-test-snapshot
    kind: VolumeSnapshot
    apiGroup: <http://snapshot.storage.k8s.io|snapshot.storage.k8s.io>
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Rocky:
Thank you @Mohamed Ayman!