示例
更新时间 2025-10-23 18:47:52
最近更新时间: 2025-10-23 18:47:52
本节展示预配置创建快照的示例。
应用场景
HBlock源卷为luna1,快照为luna1-snapshot,在CSI中创建快照csi-static-snapshot-luna1。
操作步骤
创建VolumeSnapshotContent的配置文件snapshot-content-luna1.yaml。
apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshotContent metadata: name: csi-static-snapshot-content1 spec: deletionPolicy: Delete driver: stor.csi.k8s.io source: snapshotHandle: stor1:lun01a:lun01a-snap2 volumeSnapshotRef: name: csi-static-snapshot-lun01a namespace: default创建VolumeSnapshot的配置文件snapshot-static-snapshot-luna1.yaml。
apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshot metadata: name: csi-static-snapshot-lun01a namespace: default spec: source: volumeSnapshotContentName: csi-static-snapshot-content1应用VolumeSnapshotContent和VolumeSnapshot的配置文件。
[root@k8s-master stor-examp]# kubectl apply -f snapshot-content-luna1.yaml volumesnapshotcontent.snapshot.storage.k8s.io/csi-static-snapshot-content1 created [root@k8s-master stor-examp]# kubectl apply -f snapshot-static-snapshot-luna1.yaml volumesnapshot.snapshot.storage.k8s.io/csi-static-snapshot-lun01a created查看快照。
说明
使用查看快照详情的命令查看时,Labels会显示快照的大小(snapshotSize),单位是字节。HBlock卷异常或上游快照删除等因素可能导致快照大小波动。修改配置文件/deploy/csi-snapshot-updater.yaml中的schedule字段,即可调整CSI同步HBlock快照的时间间隔,详见概述。
[root@k8s-master stor-examp]# kubectl get volumesnapshot NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE csi-static-snapshot-lun01a true csi-static-snapshot-content1 100Gi csi-static-snapshot-content1 10m 10m [root@k8s-master stor-examp]# kubectl describe volumesnapshot csi-static-snapshot-lun01a Name: csi-static-snapshot-lun01a Namespace: default Labels: snapshotSize=393707520 Annotations: <none> API Version: snapshot.storage.k8s.io/v1 Kind: VolumeSnapshot Metadata: Creation Timestamp: 2025-09-18T02:23:41Z Finalizers: snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection snapshot.storage.kubernetes.io/volumesnapshot-bound-protection snapshot.storage.kubernetes.io/volumesnapshot-bound-protection Generation: 1 Managed Fields: API Version: snapshot.storage.k8s.io/v1 Fields Type: FieldsV1 fieldsV1: f:metadata: f:annotations: .: f:kubectl.kubernetes.io/last-applied-configuration: f:spec: .: f:source: .: f:volumeSnapshotContentName: Manager: kubectl-client-side-apply Operation: Update Time: 2025-09-18T02:23:41Z API Version: snapshot.storage.k8s.io/v1 Fields Type: FieldsV1 fieldsV1: f:metadata: f:finalizers: f:status: .: f:boundVolumeSnapshotContentName: f:creationTime: f:readyToUse: f:restoreSize: Manager: snapshot-controller Operation: Update Time: 2025-09-18T02:24:06Z API Version: snapshot.storage.k8s.io/v1 Fields Type: FieldsV1 fieldsV1: f:metadata: f:labels: .: f:snapshotSize: Manager: Go-http-client Operation: Update Time: 2025-09-18T02:30:09Z Resource Version: 17166141 UID: 31c5a628-884f-4acb-8de2-06cc7e988acf Spec: Source: Volume Snapshot Content Name: csi-static-snapshot-content1 Status: Bound Volume Snapshot Content Name: csi-static-snapshot-content1 Creation Time: 2025-09-18T02:24:05Z Ready To Use: true Restore Size: 100Gi Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning SnapshotFinalizerError 10m snapshot-controller Failed to check and update snapshot: snapshot controller failed to update default/csi-static-snapshot-lun01a on API server: Operation cannot be fulfilled on volumesnapshots.snapshot.storage.k8s.io "csi-static-snapshot-lun01a": the object has been modified; please apply your changes to the latest version and try again Warning SnapshotContentMissing 10m snapshot-controller VolumeSnapshotContent is missing Normal SnapshotCreated 10m snapshot-controller Snapshot default/csi-static-snapshot-lun01a was successfully created by the CSI driver. Normal SnapshotReady 10m snapshot-controller Snapshot default/csi-static-snapshot-lun01a is ready to use. Normal SnapshotCreated 10m snapshot-controller Snapshot default/csi-static-snapshot-lun01a was successfully created by the CSI driver. Normal SnapshotReady 10m snapshot-controller Snapshot default/csi-static-snapshot-lun01a is ready to use.