How to Restore Volumes from Snapshots in Kubernetes Clusters

DigitalOcean Kubernetes (DOKS) is a managed Kubernetes service that lets you deploy Kubernetes clusters without the complexities of handling the control plane and containerized infrastructure. Clusters are compatible with standard Kubernetes toolchains and integrate natively with DigitalOcean Load Balancers and block storage volumes.


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