Đặt lịch xóa snapshot PVC
FPT Cloud cho phép đặt lịch xóa snapshot PVC theo tên PVC, namespace và thời gian lưu trữ (retention) tính bằng giờ hoặc ngày.
Thiết lập lịch CronJob dọn dẹp snapshot
-
Tạo
ServiceAccountđể CronJob có quyền trong cluster:apiVersion: v1kind: ServiceAccountmetadata:name: cleanup-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 đã tạo ở trên:apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: grant-cleanup-snapshot-sa-adminsubjects:- kind: ServiceAccountname: cleanup-snapshot-sanamespace: default #or any other namespace that you want to deploy the cronjob- kind: ServiceAccountname: cleanup-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-cleanup-snapshot-sa-admin -
Apply CronJob để tự động xóa snapshot PVC:
apiVersion: batch/v1kind: CronJobmetadata:name: cleanup-snapshotsspec:schedule: "0 2 * * *" #Adjust this (minute hour day(month) month day(week))timeZone: "Asia/Saigon"jobTemplate:spec:template:spec:serviceAccountName: cleanup-snapshot-sa #match with service account namecontainers:- name: snapshot-cleanupimage: registry.fke.fptcloud.com/xplat-fke/cleanup-snapshot-pvc:v0.1.0env:- name: NAMESPACEvalue: "your-pvc-namespace" #Replace with your PVC namespace- name: PVC_NAMEvalue: "your-pvc" #Replace with your PVC name- name: RETENTION_MAXvalue: "7" #or any int > 0- name: RETENTION_UNITSvalue: "days" #or "hours"restartPolicy: OnFailure
Xóa CronJob dọn dẹp
Để dừng đặt lịch xóa snapshot cho 1 PVC, xóa CronJob tương ứng.