Schedule PVC Snapshot Deletion
FPT Cloud lets you schedule deletion of PVC snapshots by PVC name, namespace, and a retention period in hours or days.
Set up a CronJob schedule for snapshot cleanup
-
Create a
ServiceAccountso the CronJob has permissions in the cluster:apiVersion: v1kind: ServiceAccountmetadata:name: cleanup-snapshot-sanamespace: default #or any other namespace that you want to deploy the cronjob -
Apply a
ClusterRoleBindingto grant permissions to that ServiceAccount.subjectsmust include every ServiceAccount across the namespaces created above: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.ioVerify it with:
kubectl get clusterrolebinding grant-cleanup-snapshot-sa-admin -
Apply a CronJob to automatically delete PVC snapshots:
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
Remove the cleanup CronJob
To stop scheduled snapshot deletion for a PVC, delete the corresponding CronJob.