Importing a snapshot into Kubernetes
How to import a CSI VolumeSnapshot in Kubernetes
Using CSI VolumeSnapshots is a powerful tool for managing persistent volumes, creating clones or restoring to a previous state. You can create VolumeSnapshots
using Kubernetes (see create snapshot) and use those snapshots within your cluster. However sometimes it is necessary to import an already existing VolumeSnapshot that was created outside your cluster, into your Kubernetes cluster.
This runbook describes how this works and shows examples on how to easily do this using acloud-toolkit snapshot import
.
Manually importing VolumeSnapshots
First you need to find the id
of your snapshot in your backend storage, such as AWS. This is the ID of the snapshot. For AWS, this looks like snap-027df45af20ee07c6
.
Preparing the VolumesnapshotContent
We are going to construct the VolumesnapshotContent
resource for Kubernetes.
A few important things to note here:
-
You need to enter your CSI Driver information for the snapshots. You can retrieve this by using
kubectl get volumesnapshotclasses
. Use theDRIVER
value forspec.driver
and theNAME
value forspec.volumeSnapshotClassName
. -
The
spec.volumeSnapshotRef
is the name and namespace we will be using to create theVolumeSnapshot
resource in your cluster, at the next step. Make sure these do not exist yet and are unique within your cluster. -
And finally, the
spec.source.snapshotHandle
value will contain the ID of the snapshot in your backend storage (i.g.snap-027df45af20ee07c6
).
You can validate the VolumeSnapshotContent
has been created in your cluster by using:
Create the VolumeSnapshot resource
Once the VolumeSnapshotContent
has been created, we can insert the VolumeSnapshot
resource:
-
Make sure the
metadata.name
andmetadata.namespace
equal those used in thespec.volumeSnapshotRef
from theVolumeSnapshotContent
. -
Use the
name
of theVolumeSnapshotContent
forspec.source.volumeSnapshotContentName
and match thespec.volumeSnapshotClassName
.
Apply this resource into your cluster and you are now ready to use the VolumeSnapshot
to resource persistent volumes within your Kubernetes Cluster!
Using acloud-toolkit
Using the CLI tool acloud-toolkit you are able to quick and easily import a snapshot ID using the above methods, by simply specifying the name
and snapshot ID
. The CLI will automatically follow the previously detailed steps and create the VolumeSnapshotContent
and VolumeSnapshot
resources within your Kubernetes cluster.
The acloud-toolkit snapshot import
subcommand will by default select your default SnapshotStorageClass
and ensure the driver and other settings are configured correctly.
How to use
How to use the snapshot import
command:
Example output
In this example, we will be importing the snapshot snap-027df45af20ee07c6
into a VolumeSnapshot
called test
within our current namespace context.
You can verify the created resources:
Last updated on