Enable snapshots for all backups
This tutorial shows three ways to enable snapshots on every Backup, instead of annotating each Backup by hand.
With snapshots enabled, a Backup detects when a topic is deleted and recreated, archives the existing backup data as a numbered snapshot, and continues backing up the new topic without manual intervention.
Prerequisites
Section titled “Prerequisites”- A Kannika Armory instance available, running on a Kubernetes environment.
- Local installation of the
kubectlbinary. - A Kafka cluster that supports topic UUIDs (KIP-516).
Snapshots only apply to topics that do not have any backup data yet. Topics that were already backed up keep using the original layout, even after the annotation is added. See Compatibility with existing backups for details.
Choose an approach
Section titled “Choose an approach”| Approach | Existing Backups | New Backups | Best for |
|---|---|---|---|
| kubectl | Yes | No | A one-off change on a cluster |
| Kustomize | Yes | Yes | Backups managed as manifests in Git |
| Kyverno | No | Yes | Backups created from the console or API |
Option A: kubectl
Section titled “Option A: kubectl”Annotate every Backup in every namespace:
kubectl annotate backups.kannika.io --all --all-namespaces \ io.kannika/experimental-snapshots=trueA Backup that already has the annotation is left unchanged,
and kubectl reports an error for it.
Add --overwrite to also set the annotation on those Backups,
for example to turn snapshots on for a Backup where they were explicitly turned off.
The operator redeploys each annotated Backup with snapshots enabled.
This only changes the Backups that exist when you run the command. Backups that are created later do not get the annotation.
Option B: Kustomize
Section titled “Option B: Kustomize”If your Backups are managed as manifests, add the annotation with a Kustomize patch that targets every Backup.
Given a backups/ directory that holds the Backup manifests,
create a kustomization.yaml next to it:
resources: - backups/
patches: - target: group: kannika.io kind: Backup patch: |- apiVersion: kannika.io/v1alpha kind: Backup metadata: name: ignored annotations: io.kannika/experimental-snapshots: "true"The target selects every Backup,
so the name in the patch is ignored.
Preview the result:
kubectl kustomize .Apply it:
kubectl apply -k .Every Backup that is added to the backups/ directory later gets the annotation as well.
Option C: Kyverno
Section titled “Option C: Kyverno”Backups that are created from the console or the API are not part of your manifests. A Kyverno mutate policy adds the annotation to every Backup when it is created or updated, no matter where it comes from.
This option requires Kyverno to be installed on the cluster.
Create a file named kannika-enable-snapshots.clusterpolicy.yaml:
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata: name: kannika-enable-snapshotsspec: rules: - name: add-experimental-snapshots match: any: - resources: kinds: - kannika.io/v1alpha/Backup mutate: patchStrategicMerge: metadata: annotations: +(io.kannika/experimental-snapshots): "true"The +(...) anchor only adds the annotation when it is not set yet,
so a Backup where snapshots are explicitly turned off with "false" keeps that value.
Apply the policy:
kubectl apply -f kannika-enable-snapshots.clusterpolicy.yamlThe policy only mutates Backups when they are created or updated. To enable snapshots on the Backups that already exist, run the command from Option A once.
Verify the result
Section titled “Verify the result”List the Backups with the value of the annotation:
kubectl get backups.kannika.io --all-namespaces \ -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,SNAPSHOTS:.metadata.annotations.io\.kannika/experimental-snapshots'NAMESPACE NAME SNAPSHOTSkannika-data orders-backup truekannika-data users-backup trueA Backup without the annotation shows <none>.
Summary
Section titled “Summary”In this tutorial, you learned how to enable snapshots on every Backup:
- With
kubectl annotate, for the Backups that exist today - With a Kustomize patch, for Backups that are managed as manifests
- With a Kyverno policy, for every Backup that is created or updated from now on
See Snapshots to restore from a specific snapshot version, or to list the snapshots of a topic.

