Skip to main content

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​

  1. Create a ServiceAccount so the CronJob has permissions in the cluster:

    apiVersion: v1
    kind: ServiceAccount
    metadata:
    name: snapshot-sa
    namespace: default #or any other namespace that you want to deploy the cronjob
  2. Apply a ClusterRoleBinding to grant permissions to that ServiceAccount. subjects must include every ServiceAccount across the namespaces where you'll run the CronJob:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
    name: grant-snapshot-sa-admin
    subjects:
    - kind: ServiceAccount
    name: snapshot-sa
    namespace: default #or any other namespace that you want to deploy the cronjob
    - kind: ServiceAccount
    name: snapshot-sa
    namespace: namespace1 #if user wants to have multiple cronjob in multiple namespace
    roleRef:
    kind: ClusterRole
    name: cluster-admin
    apiGroup: rbac.authorization.k8s.io

    Verify it with:

    kubectl get clusterrolebinding grant-snapshot-sa-admin -oyaml
  3. Apply a CronJob to automatically schedule PVC snapshots:

    apiVersion: batch/v1
    kind: CronJob
    metadata:
    name: pvc-snapshot #or any other name that you want to set
    namespace: default #or any other namespace that you want to deploy the cronjob, but must be in the same namespace with ServiceAccount and ClusterRoleBinding
    spec:
    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 previously
    containers:
    - name: pvc-snapshot
    image: registry.fke.fptcloud.com/xplat-fke/snapshot-pvc:v0.1.0
    env:
    - name: PVC_NAME
    value: "your-pvc-name" #name of the PVC that you want to apply Cronjob to
    - name: NAMESPACE
    value: "your-pvc-namespace" #namespace of the above PVC
    restartPolicy: 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 name
  • example — namespace name
  • 2412020736 — 24 (year), 12 (month), 02 (day), 07 (hour), 36 (minute), UTC+0
note

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.