Skip to content

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.

  • A Kannika Armory instance available, running on a Kubernetes environment.
  • Local installation of the kubectl binary.
  • 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.

ApproachExisting BackupsNew BackupsBest for
kubectlYesNoA one-off change on a cluster
KustomizeYesYesBackups managed as manifests in Git
KyvernoNoYesBackups created from the console or API

Annotate every Backup in every namespace:

Terminal window
kubectl annotate backups.kannika.io --all --all-namespaces \
io.kannika/experimental-snapshots=true

A 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.

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:

kustomization.yaml
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:

Terminal window
kubectl kustomize .

Apply it:

Terminal window
kubectl apply -k .

Every Backup that is added to the backups/ directory later gets the annotation as well.

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:

kannika-enable-snapshots.clusterpolicy.yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: kannika-enable-snapshots
spec:
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:

Terminal window
kubectl apply -f kannika-enable-snapshots.clusterpolicy.yaml

The 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.

List the Backups with the value of the annotation:

Terminal window
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 SNAPSHOTS
kannika-data orders-backup true
kannika-data users-backup true

A Backup without the annotation shows <none>.

In this tutorial, you learned how to enable snapshots on every Backup:

  1. With kubectl annotate, for the Backups that exist today
  2. With a Kustomize patch, for Backups that are managed as manifests
  3. 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.