How to Restore Volumes from Snapshots in Kubernetes Clusters

DigitalOcean Kubernetes (DOKS) is a managed Kubernetes service. Deploy Kubernetes clusters with a fully managed control plane, high availability, autoscaling, and native integration with DigitalOcean Load Balancers and volumes. DOKS clusters are compatible with standard Kubernetes toolchains and the DigitalOcean API and CLI.


In Kubernetes, a volume snapshot is a point-in-time copy of the contents of a Kubernetes cluster. You can use snapshots to back up a cluster’s data or copy the data to another resource without needing to create a new volume.

To import an existing snapshot into DigitalOcean as a volume, 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: snapshot.storage.k8s.io
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi