Đặt lịch snapshot PVC
Bên cạnh tính năng snapshot PV theo yêu cầu, FPT Cloud cho phép đặt lịch snapshot PVC định kỳ bằng CronJob của Kubernetes.
Thiết lập lịch CronJob cho snapshot PVC
-
Tạo
ServiceAccountđể CronJob có quyền trong cluster:apiVersion: v1kind: ServiceAccountmetadata:name: snapshot-sanamespace: default #or any other namespace that you want to deploy the cronjob -
Apply
ClusterRoleBindingđể cấp quyền cho ServiceAccount đó.subjectsphải liệt kê đủ mọi ServiceAccount ở các namespace bạn sẽ chạy CronJob:apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: grant-snapshot-sa-adminsubjects:- kind: ServiceAccountname: snapshot-sanamespace: default #or any other namespace that you want to deploy the cronjob- kind: ServiceAccountname: snapshot-sanamespace: namespace1 #if user wants to have multiple cronjob in multiple namespaceroleRef:kind: ClusterRolename: cluster-adminapiGroup: rbac.authorization.k8s.ioKiểm tra bằng:
kubectl get clusterrolebinding grant-snapshot-sa-admin -oyaml -
Apply CronJob để tự động đặt lịch snapshot PVC:
apiVersion: batch/v1kind: CronJobmetadata:name: pvc-snapshot #or any other name that you want to setnamespace: default #or any other namespace that you want to deploy the cronjob, but must be in the same namespace with ServiceAccount and ClusterRoleBindingspec:schedule: "0 * * * *" #Adjust this (minute hour day(month) month day(week))timeZone: "Asia/Saigon"jobTemplate:spec:template:spec:serviceAccountName: snapshot-sa #Remember to match the name of ServiceAccount that deployed previouslycontainers:- name: pvc-snapshotimage: registry.fke.fptcloud.com/xplat-fke/snapshot-pvc:v0.1.0env:- name: PVC_NAMEvalue: "your-pvc-name" #name of the PVC that you want to apply Cronjob to- name: NAMESPACEvalue: "your-pvc-namespace" #namespace of the above PVCrestartPolicy: OnFailure
Xem danh sách snapshot
Liệt kê snapshot để kiểm tra CronJob đang hoạt động:
kubectl get volumesnapshots.snapshot.storage.k8s.io -A
NAMESPACE NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
example wp-pv-claim-example-2412020736 true wp-pv-claim 20Gi csi-cinder-snapclass snapcontent-045fe85e-7471-4bfb-9a55-2ed2ed2263dd 64m 64m
example wp-pv-claim-example-2412020836 true wp-pv-claim 20Gi csi-cinder-snapclass snapcontent-fd1333bc-70f6-417f-a91d-10349aa0647d 4m11s 4m11s
Tên snapshot wp-pv-claim-example-2412020736 được diễn giải như sau:
wp-pv-claim— tên PVCexample— tên namespace2412020736— 24 (năm), 12 (tháng), 02 (ngày), 07 (giờ), 36 (phút), UTC+0
Mỗi PVC chỉ hỗ trợ 1 CronJob — tạo nhiều CronJob nếu cần đặt lịch cho nhiều PVC hoặc nhiều lịch khác nhau cho cùng 1 PVC. Khi Job mới chạy, nó tạo 1 pod thực hiện snapshot; kiểm tra bằng kubectl get volumesnapshots.snapshot.storage.k8s.io -n <namespace> hoặc kubectl get jobs.batch -n <namespace>.
Image do FPT Cloud cung cấp không có tính năng retention, nên tự xóa các snapshot cũ để tránh đầy quota disk storage.
Xóa lịch CronJob
Để dừng đặt lịch snapshot cho 1 PVC, xóa CronJob tương ứng.