Schedule PVC Snapshots
Alongside the on-demand PV snapshot feature, FPT Cloud lets you schedule recurring PVC snapshots with a Kubernetes CronJob.
Set up a CronJob schedule for PVC snapshots
-
Create a
ServiceAccountso the CronJob has permissions in the cluster:apiVersion: v1kind: ServiceAccountmetadata:name: 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 where you'll run the 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.ioVerify it with:
kubectl get clusterrolebinding grant-snapshot-sa-admin -oyaml -
Apply a CronJob to automatically schedule PVC snapshots:
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
Read the snapshot list
List snapshots to check the CronJob is working:
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
The snapshot name wp-pv-claim-example-2412020736 breaks down as:
wp-pv-claim— PVC nameexample— namespace name2412020736— 24 (year), 12 (month), 02 (day), 07 (hour), 36 (minute), UTC+0
Each PVC supports only one CronJob — create multiple CronJobs if you need to schedule multiple PVCs or multiple schedules for one PVC. When a new Job runs, it creates a pod that performs the snapshot; verify with kubectl get volumesnapshots.snapshot.storage.k8s.io -n <namespace> or kubectl get jobs.batch -n <namespace>.
The FPT Cloud-provided image has no retention feature, so delete old snapshots yourself to avoid filling up your disk storage quota.
Remove the CronJob schedule
To stop scheduled snapshots for a PVC, delete the corresponding CronJob.