Snapshot Persistent Volume trên Kubernetes
Tính năng snapshot Persistent Volume (PV) tạo một bản sao dữ liệu PV tại một thời điểm trong cluster M-FKE, giúp bạn backup dữ liệu cluster hoặc copy dữ liệu sang resource khác mà không cần tạo volume mới.
Để tạo snapshot, apply file YAML định nghĩa PVC cần snapshot — component VolumeSnapshotClass xử lý phần còn lại, và khi resource snapshot xuất hiện trong cluster, snapshot tương ứng sẽ được tạo trong VPC. Để snapshot theo lịch định kỳ, tạo script gọi Kubernetes API theo chu kỳ. Xem tài liệu Kubernetes về volume snapshot để biết thêm.
Cấu hình VolumeSnapshotClass
Nếu cluster chưa có, tạo một VolumeSnapshotClass:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: csi-cinder-snapclass
annotations:
snapshot.storage.kubernetes.io/is-default-class: "true"
driver: cinder.csi.openstack.org
deletionPolicy: Delete
parameters:
type: [type-storage-policy]
force-create: "true"
[type-storage-policy] là loại storage policy bạn đang dùng — lấy giá trị này ở field parameters/type trong cấu hình StorageClass mặc định.
Tạo snapshot
Bạn cần có sẵn 1 volume đang dùng trong cluster (tạo bởi PVC). Giả sử cấu hình PVC như sau:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
Tạo VolumeSnapshot để snapshot volume đó:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: new-snapshot-test
namespace: default
spec:
volumeSnapshotClassName: csi-cinder-snapclass
source:
persistentVolumeClaimName: test-pvc
volumeSnapshotClassName— FPT Cloud có sẵn 1 class mặc định; dùngVolumeSnapshotClassphù hợp với nhu cầu.persistentVolumeClaimName— tên PVC cần snapshot.
Kiểm tra snapshot
Sau khi tạo, kiểm tra snapshot tại Compute Engine → Snapshot trong Unify Portal.

Bạn cũng có thể kiểm tra bằng kubectl:
kubectl get volumesnapshots.snapshot.storage.k8s.io -n default