I wrote a CronJob that periodically takes volume snapshot of my PVC. Below is the CronJob file:
kind: CronJob
metadata:
name: mycronjob
spec:
schedule: "*/2 * * * *" # Run the job every 2 minutes
jobTemplate:
spec:
template:
spec:
containers:
- name: webserver-container
image: kubectl:latest
command:
- /bin/sh
- -c
- /app/script.sh
volumeMounts:
- name: script-volume
mountPath: /app
restartPolicy: OnFailure
volumes:
- name: script-volume
configMap:
name: script-configmap
The Volume Snapshot file looks like this:
kind: VolumeSnapshot
metadata:
name: snap-shot-test
spec:
volumeSnapshotClassName: csi-snapclass
source:
persistentVolumeClaimName: my-test-apps
And here is the script file:
#!/bin/bash
kubectl apply -f volumesnapshot.yml
First time the cronjob is successfully executed, but after that it says volumesnapshot.snapshot.storage.k8s.io/snap-shot-test unchanged
How can I periodically take volumesnapshot of a PVC with having latest 2 copies of the snapshot?