The VirtualMachine Snapshot Scheduler is a Kubernetes operator designed to automate the lifecycle of KubeVirt VirtualMachineSnapshot resources. It creates snapshots at defined intervals using cron expressions and manages their retention.
- Cron-based Scheduling: Automatically creates
VirtualMachineSnapshotobjects at specified intervals. - Multiple VM Support: Selects VirtualMachines to snapshot using a
LabelSelector. - Retention Management: Automatically deletes old snapshots based on a maximum count or TTL (Time to Live).
- Disable Schedule: Disable snapshot creation by setting
disabled: truewhile maintaining existing snapshots. - Leader Election: Supports high availability with leader election.
- CRD Configuration: Fully configurable with simple YAML manifests.
apiVersion: snapscheduler.kubevirt.io/v1alpha1
kind: VirtualMachineSnapshotSchedule
metadata:
name: example-schedule
namespace: default
spec:
# Standard cron expression for scheduling snapshots
# Also supports descriptors (@daily, @monthly, @yearly...
schedule: "0 2 * * *"
# Selection of VirtualMachines to snapshot
# Supports both matchLabels and matchExpressions
virtualMachineSelector:
matchLabels:
vm.kubevirt.io/name: my-vm
matchExpressions:
- key: environment
operator: In
values:
- production
# Retention policies (can be used together)
maxCount: 7 # Keep only the last 7 snapshots
ttl: "168h" # Keep snapshots for 7 days (e.g., 24h, 1h, 30m)
# Template for the created VirtualMachineSnapshot objects
snapshotTemplate:
metadata:
labels:
backup-type: scheduled
# Set to true to pause the schedule without deleting it
disabled: falseTo enable scheduled snapshots for your VirtualMachines, create a VirtualMachineSnapshotSchedule resource.
apiVersion: snapscheduler.kubevirt.io/v1alpha1
kind: VirtualMachineSnapshotSchedule
metadata:
name: daily-backup
spec:
schedule: "0 2 * * *" # Every day at 2 AM
maxCount: 7 # Keep last 7 snapshots
virtualMachineSelector:
matchLabels:
vm.kubevirt.io/name: my-vmapiVersion: snapscheduler.kubevirt.io/v1alpha1
kind: VirtualMachineSnapshotSchedule
metadata:
name: production-vms-backup
spec:
schedule: "0 */4 * * *" # Every 4 hours
ttl: "48h" # Keep snapshots for 48 hours
virtualMachineSelector:
matchLabels:
environment: production
snapshotTemplate:
metadata:
labels:
backup-type: scheduledThe controller can be configured using command-line flags or through the Helm chart:
| Flag | Default | Description |
|---|---|---|
--kubeconfig |
- | Path to a kubeconfig file. |
--leader-elect |
false |
Enable leader election. |
--enable-owner-references |
false |
Enable owner references and finalizers for snapshots. |
A Helm chart is provided in the charts/vmsnapshot-scheduler directory.
helm install vmsnapshot-scheduler ./charts/vmsnapshot-scheduler -n vmsnapshot-scheduler --create-namespaceEnsure you configure the namespace correctly in your values or via --set.
Enable enableOwnerReferences if you want to use owner references and finalizers for snapshots.
When VirtualMachineSnapshotSchedule objects are deleted, all the related VirtualMachineSnapshot objects will be deleted as well.
- Go 1.25+
- Docker (optional, for containerized builds)
make buildmake docker-build IMG=vmsnapshot-scheduler:latest