動態創建快照
更新時間 2025-09-23 16:29:02
最近更新時間: 2025-09-23 16:29:02
分享文章
本節主要介紹動態創建快照的步驟。
前提條件
已經創建HBlock相關的PVC,且對應的HBlock卷為Local模式。
在執行此操作之前,請確保源卷的所有數據已持久化,即如果源卷已被客戶端掛載,需確保客戶端的數據都已經同步到卷上。創建快照前:
如果是block模式的卷:在客戶端執行sync命令。
如果是filesystem模式的卷:如果客戶端支持sync -f(可以通過sync --help命令查看是否支持),在客戶端執行sync -f命令;否則在客戶端執行sync命令。
操作步驟
創建VolumeSnapshotClass的YAML配置文件。
apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshotClass metadata: # If there is a conflict with other VolumeSnapshotClass, you can change it to another name name: csi-dynamic-snapclass # Set to the actual driver name driver: stor.csi.k8s.io deletionPolicy: DeleteVolumeSnapshotClass的YAML配置文件參數:
參數 描述 是否必填 metadata.name VolumeSnapshotClass的名稱。 是 driver HBlock CSI驅動名稱。
取值:HBlock CSI安裝時的驅動名稱。
是 創建VolumeSnapshot的YAML配置文件。
apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshot metadata: name: csi-dynamic-snapshot # Set to the actual namespace namespace: default spec: # If there is a conflict with other VolumeSnapshotClass, you can change it to another name volumeSnapshotClassName: csi-dynamic-snapclass source: persistentVolumeClaimName: csi-pvc-localVolumeSnapshot的YAML配置文件參數:
參數 描述 是否必填 metadata.name CSI中快照的名稱。 是 metadata.namespace 命名空間。
取值:HBlock CSI安裝時綁定的Kubernetes命名空間名稱。
是 spec.volumeSnapshotClassName VolumeSnapshotClass的名稱。 是 spec.source.persistentVolumeClaimName CSI中PVC的名字。 是 應用VolumeSnapshotContent和VolumeSnapshot的配置文件。
kubectl apply -f VolumeSnapshotClass.yaml kubectl apply -f VolumeSnapshot.yaml查看快照。
kubectl get volumesnapshot [snapshotName] [ -n namespace ]