VolumeSnapshot
PersistentVolumeClaim
object, creating and deleting this object represents the user's desire to create or delete a cluster resource (snapshot).VolumeSnapshotContent
PersistentVolume
object, it represents the resource already serviced by the cluster (snapshot).PersistentVolumeClaim
and PersistentVolume
objects, when the snapshot is created, the VolumeSnapshotContent
object VolumeSnapshotContent
bound to the VolumeSnapshot
for which it was created (one-to-one mapping is used).VolumeSnapshotClass
PersistentVolumeClaim
a new DataSource
field: type PersistentVolumeClaimSpec struct { AccessModes []PersistentVolumeAccessMode Selector *metav1.LabelSelector Resources ResourceRequirements VolumeName string StorageClassName *string VolumeMode *PersistentVolumeMode DataSource *TypedLocalObjectReference }
--feature-gates=VolumeSnapshotDataSource=true
VolumeSnapshotClass
object and specifying the CSI driver in the snapshotter
field. In the following example with VolumeSnapshotClass
this driver is com.example.csi-driver
. Each snapshot provider requires at least one VolumeSnapshotClass
object. It is also possible to define the default VolumeSnapshotClass
for each CSI driver β this is done by setting the snapshot.storage.kubernetes.io/is-default-class: "true"
annotation in the class definition: apiVersion: snapshot.storage.k8s.io/v1alpha1 kind: VolumeSnapshotClass metadata: name: default-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" snapshotter: com.example.csi-driver apiVersion: snapshot.storage.k8s.io/v1alpha1 kind: VolumeSnapshotClass metadata: name: csi-snapclass snapshotter: com.example.csi-driver parameters: fakeSnapshotOption: foo csiSnapshotterSecretName: csi-secret csiSnapshotterSecretNamespace: csi-namespace
fakeSnapshotOption: foo
parameter and all the mentioned secrets will be passed to the CSI driver during the creation and deletion of the snapshot. The CSI external-snapshotter saves the csiSnapshotterSecretName
and csiSnapshotterSecretNamespace
parameter keys by default.VolumeSnapshotClass
object VolumeSnapshotClass
defined and there is a volume from which you want to take a snapshot, you can perform this operation by creating a VolumeSnapshot
object.kind
- PersistentVolumeClaim
indicated here;name
is the actual name of the PVC object.VolumeSnapshot
object. apiVersion: snapshot.storage.k8s.io/v1alpha1 kind: VolumeSnapshot metadata: name: new-snapshot-demo namespace: demo-namespace spec: snapshotClassName: csi-snapclass source: name: mypvc kind: PersistentVolumeClaim
VolumeSnapshot
specification can VolumeSnapshot
a VolumeSnapshotClass
, which contains information about which CSI driver will be used to create the snapshot. As previously reported, after creating the VolumeSnapshot
object VolumeSnapshot
the fakeSnapshotOption: foo
parameter and all the mentioned VolumeSnapshotClass
secrets are passed to the CSI plugin com.example.csi-driver
in the CreateSnapshot
call.VolumeSnapshotContent
object that represents the new snapshot and binds this object to the VolumeSnapshot
, making it ready for use. If the CSI driver cannot create snapshots and returns an error, the snapshot controller reports this error in the status of the VolumeSnapshot
object and does not make new attempts (this behavior differs from other controllers in Kubernetes - it is implemented in order not to create snapshots in unpredictable times) .snapshotter
in the default class must match the CSI driver pointed to by the provisioner
in the PVC storage class.VolumeSnapshot
that a VolumeSnapshot
object VolumeSnapshot
created and associated with a VolumeSnapshotContent
by using the kubectl describe volumesnapshot
command kubectl describe volumesnapshot
:Ready
should be true
in Status
, which will indicate that the snapshot volume is ready for use.Creation Time
field shows when the snapshot was actually made.Restore Size
field - the minimum size of the volume to restore snapshot.Snapshot Content Name
field in the specification points to a VolumeSnapshotContent
object created for this snapshot.VolumeSnapshotContent
object that will represent this snapshot. Since VolumeSnapshotContent
is an API object that is not bound to a namespace, only a system administrator has permission to create it.VolumeSnapshotContent
object VolumeSnapshotContent
created, the user can create another object β the VolumeSnapshot
β that will point to it. The external-snapshotter controller will mark the snapshot as ready after checking for the existence and correctness of the connection between the VolumeSnapshot
and VolumeSnapshotContent
. Snapshot is ready for use in Kubernetes when this connection is established.VolumeSnapshotContent
object should be created with the following fields representing the pre-provisioned snapshot:csiVolumeSnapshotSource
- information identifying snapshot:snapshotHandle
- name / identifier for snapshot. Obligatory field;driver
- CSI driver used to work with this volume. Obligatory field. Must match the name of the snapshotter
in the controller (snapshot controller);creationTime
and restoreSize
β these are optional for pre-prepared volumes. The external-snapshotter controller will automatically update them after creating the snapshot.volumeSnapshotRef
- a pointer to the VolumeSnapshot
object to which this object (ie, VolumeSnapshotContent
) should be VolumeSnapshotContent
:name
and namespace
- the name and namespace of the VolumeSnapshot
object, the contents of which are bound;UID
- optional (for pre-prepared volumes) field. The external-snapshotter controller will automatically update this field after binding. If the user specifies this field, you must ensure that it corresponds to the snapshot UID for which the binding occurs. If there is no match, the content is considered irrelevant (orphan-object) and therefore the controller will delete both it and its associated snapshot.snapshotClassName
is an optional field. The external-snapshotter controller will automatically update it after binding. apiVersion: snapshot.storage.k8s.io/v1alpha1 kind: VolumeSnapshotContent metadata: name: static-snapshot-content spec: csiVolumeSnapshotSource: driver: com.example.csi-driver snapshotHandle: snapshotcontent-example-id volumeSnapshotRef: kind: VolumeSnapshot name: static-snapshot-demo namespace: demo-namespace
VolumeSnapshot
object must be created so that the user can work with snapshot. In him:snapshotClassName
is the name of the snapshot class of the volume. Optional field. If set, the snapshotter
field in the snapshot class must match the name of the snapshot controller. If not set, the controller will search for the default snapshot class;snapshotContentName
is the name of the contents of the snapshot volume. Required field for pre-prepared volumes. apiVersion: snapshot.storage.k8s.io/v1alpha1 kind: VolumeSnapshot metadata: name: static-snapshot-demo namespace: demo-namespace spec: snapshotClassName: csi-snapclass snapshotContentName: static-snapshot-content
Ready
field (in Status
) to True
, indicating that the snapshot is ready for use.dataSource
field in PersistentVolumeClaim
. It has three parameters:name
- the name of the VolumeSnapshot
object that represents the source snapshot;kind
- must be specified as a VolumeSnapshot
;apiGroup
- should be snapshot.storage.k8s.io
.VolumeSnapshot
object β corresponds to the namespace of the PersistentVolumeClaim
object. apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-restore Namespace: demo-namespace spec: storageClassName: csi-storageclass dataSource: name: new-snapshot-demo kind: VolumeSnapshot apiGroup: snapshot.storage.k8s.io accessModes: - ReadWriteOnce resources: requests: storage: 1Gi
PersistentVolumeClaim
object is created, it will provide for the provisioning of a new volume, previously filled with data from the specified snapshot.CREATE_DELETE_SNAPSHOT
and LIST_SNAPSHOTS
, and additional RPC controllers are CreateSnapshot
: CreateSnapshot
, DeleteSnapshot
, ListSnapshots
. See the CSI specification for details.VolumeSnapshot
and VolumeSnapshotContent
, invoking the CreateSnapshot
and DeleteSnapshot
for the CSI endpoint. The CSI external-provisioner sidecar-container has also been updated to support recovery of the volume from snapshot using the new dataSource
field in the PVC.StatefulSet
, as shown in the diagram below:PersistentVolumeClaim
from snapshot is not supported: i.e. The provisioning of a new volume from snapshot works, but not updating an existing PersistentVolumeClaim
so that it points to a new volume and the PVC rolls back to an earlier state (only the use of a new volume created from snapshot through the new PV / PVC is supported).Source: https://habr.com/ru/post/426133/
All Articles