mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-07 00:48:01 +01:00
152 lines
5.1 KiB
Plaintext
152 lines
5.1 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * storage/container_storage_interface/persistent-storage-csi-snapshots.adoc
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
[id="persistent-storage-csi-snapshots-create_{context}"]
|
|
= Creating a volume snapshot
|
|
|
|
When you create a `VolumeSnapshot` object, {product-title} creates a volume snapshot.
|
|
|
|
|
|
.Prerequisites
|
|
* Logged in to a running {product-title} cluster.
|
|
* A PVC created using a CSI driver that supports `VolumeSnapshot` objects.
|
|
* A storage class to provision the storage back end.
|
|
* No pods are using the persistent volume claim (PVC) that you want to take a snapshot of.
|
|
+
|
|
[WARNING]
|
|
====
|
|
Creating a volume snapshot of a PVC that is in use by a pod can cause unwritten data and cached data to be excluded from the snapshot. To ensure that all data is written to the disk, delete the pod that is using the PVC before creating the snapshot.
|
|
====
|
|
|
|
.Procedure
|
|
|
|
To dynamically create a volume snapshot:
|
|
|
|
. Create a file with the `VolumeSnapshotClass` object described by the following YAML:
|
|
|
|
+
|
|
.volumesnapshotclass.yaml
|
|
[source,yaml]
|
|
----
|
|
apiVersion: snapshot.storage.k8s.io/v1
|
|
kind: VolumeSnapshotClass
|
|
metadata:
|
|
name: csi-hostpath-snap
|
|
driver: hostpath.csi.k8s.io <1>
|
|
deletionPolicy: Delete
|
|
----
|
|
+
|
|
<1> The name of the CSI driver that is used to create snapshots of this `VolumeSnapshotClass` object. The name must be the same as the `Provisioner` field of the storage class that is responsible for the PVC that is being snapshotted.
|
|
+
|
|
[NOTE]
|
|
====
|
|
Depending on the driver that you used to configure persistent storage, additional parameters might be required. You can also use an existing `VolumeSnapshotClass` object.
|
|
====
|
|
|
|
. Create the object you saved in the previous step by entering the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f volumesnapshotclass.yaml
|
|
----
|
|
|
|
. Create a `VolumeSnapshot` object:
|
|
|
|
+
|
|
.volumesnapshot-dynamic.yaml
|
|
[source,yaml]
|
|
----
|
|
apiVersion: snapshot.storage.k8s.io/v1
|
|
kind: VolumeSnapshot
|
|
metadata:
|
|
name: mysnap
|
|
spec:
|
|
volumeSnapshotClassName: csi-hostpath-snap <1>
|
|
source:
|
|
persistentVolumeClaimName: myclaim <2>
|
|
----
|
|
+
|
|
<1> The request for a particular class by the volume snapshot. If the `volumeSnapshotClassName` setting is absent and there is a default volume snapshot class, a snapshot is created with the default volume snapshot class name. But if the field is absent and no default volume snapshot class exists, then no snapshot is created.
|
|
+
|
|
<2> The name of the `PersistentVolumeClaim` object bound to a persistent volume. This defines what you want to create a snapshot of. Required for dynamically provisioning a snapshot.
|
|
|
|
. Create the object you saved in the previous step by entering the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f volumesnapshot-dynamic.yaml
|
|
----
|
|
|
|
|
|
To manually provision a snapshot:
|
|
|
|
. Provide a value for the `volumeSnapshotContentName` parameter as the source for the snapshot, in addition to defining volume snapshot class as shown above.
|
|
+
|
|
.volumesnapshot-manual.yaml
|
|
[source,yaml]
|
|
----
|
|
apiVersion: snapshot.storage.k8s.io/v1
|
|
kind: VolumeSnapshot
|
|
metadata:
|
|
name: snapshot-demo
|
|
spec:
|
|
source:
|
|
volumeSnapshotContentName: mycontent <1>
|
|
----
|
|
<1> The `volumeSnapshotContentName` parameter is required for pre-provisioned snapshots.
|
|
|
|
. Create the object you saved in the previous step by entering the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f volumesnapshot-manual.yaml
|
|
----
|
|
|
|
.Verification
|
|
After the snapshot has been created in the cluster, additional details about the snapshot are available.
|
|
|
|
. To display details about the volume snapshot that was created, enter the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc describe volumesnapshot mysnap
|
|
----
|
|
+
|
|
The following example displays details about the `mysnap` volume snapshot:
|
|
+
|
|
.volumesnapshot.yaml
|
|
[source,yaml]
|
|
----
|
|
apiVersion: snapshot.storage.k8s.io/v1
|
|
kind: VolumeSnapshot
|
|
metadata:
|
|
name: mysnap
|
|
spec:
|
|
source:
|
|
persistentVolumeClaimName: myclaim
|
|
volumeSnapshotClassName: csi-hostpath-snap
|
|
status:
|
|
boundVolumeSnapshotContentName: snapcontent-1af4989e-a365-4286-96f8-d5dcd65d78d6 <1>
|
|
creationTime: "2020-01-29T12:24:30Z" <2>
|
|
readyToUse: true <3>
|
|
restoreSize: 500Mi
|
|
----
|
|
<1> The pointer to the actual storage content that was created by the controller.
|
|
<2> The time when the snapshot was created. The snapshot contains the volume content that was available at this indicated time.
|
|
<3> If the value is set to `true`, the snapshot can be used to restore as a new PVC.
|
|
+
|
|
If the value is set to `false`, the snapshot was created. However, the storage back end needs to perform additional tasks to make the snapshot usable so that it can be restored as a new volume. For example, Amazon Elastic Block Store data might be moved to a different, less expensive location, which can take several minutes.
|
|
|
|
. To verify that the volume snapshot was created, enter the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc get volumesnapshotcontent
|
|
----
|
|
+
|
|
The pointer to the actual content is displayed. If the `boundVolumeSnapshotContentName` field is populated, a `VolumeSnapshotContent` object exists and the snapshot was created.
|
|
|
|
. To verify that the snapshot is ready, confirm that the `VolumeSnapshot` object has `readyToUse: true`.
|