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 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 DigitalOcean snapshot into the DigitalOcean platform as a Kubernetes snapshot, you need to apply three new YAML files to link your existing snapshot, create a local snapshot, and request for space on your Kubernetes cluster.
First, find the existing snapshot’s ID by making a request to our API or running the following command:
doctl compute snapshot list
VolumeShapshotContent
SnapshotCreate a VolumeSnapshotContent
snapshot called snapshotcontent.yaml
. This file sets your existing snapshot as the source of data for import. Write the following content, replacing <your-snapshot-ID>
with your snapshot ID:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotContent
metadata:
name: manually-created-snapshot-content
spec:
deletionPolicy: Delete
driver: testdriver.csi.k8s.io
source:
snapshotHandle: your-snapshot-ID
volumeSnapshotRef:
name: test-snapshot
namespace: default
This file has two name
fields: the first is the snapshot’s name and the second is the paired snapshot request’s name. You can pick any name you want for them, but the names must match between all the files in this guide.
The deletionPolicy
is set to Retain
. This setting preserves the VolumeSnapshotContent
and the DigitalOcean snapshot resource when you delete the VolumeSnapshot
, instead of automatically deleting them. To delete all three files together when deleting VolumeSnapshot
, change this value to Delete
.
Save and exit the file, then apply it:
kubectl apply -f snapshotcontent.yaml
VolumeSnapshot
Snapshot RequestCreate a VolumeSnapshot
snapshot request called snapshot.yml
. This file creates a local snapshot with the previous file’s data. Write the following content, ensuring that the name
fields match up with the previous file:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: manually-created-snapshot
spec:
source:
volumeSnapshotContentName: test-content
Save and exit the file, then apply it:
kubectl apply -f snapshot.yaml
Lastly, source the snapshot from a PersistentVolumeClaim
(PVC) request. The file requests space for the new data on the Kubernetes cluster. Create a file called pvc.yaml
and write the following content, ensuring that the name
fields match up with the previous files:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-restore
namespace: default
spec:
storageClassName: testdriver.csi.k8s.io
dataSource:
name: manually-created-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Save and exit the file, then apply it:
kubectl apply -f pvc.yaml
This command causes the PersistentVolumeClaim
to dynamically create a PersistentVolume
.
You have now imported a DigitalOcean snapshot as a Kubernetes snapshot.