Annotations Examples
Here are a few examples demonstrating how to set up Bacula annotations within Kubernetes Pods and PVCs.
When dealing with Kubernetes deployments, the annotations must be placed in the Pod
template’s specification, or .template.spec field:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-mysql
labels:
app: wordpress
tier: mysql
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
annotations:
bacula/backup.mode: standard
bacula/backup.volumes: mysql-pv-claim
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: changeme
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
In the example below, a simple Linux command, sync, is used to
synchronize cached writes to persistent storage before volume cloning.
apiVersion: v1
kind: Pod
metadata:
name: app1
namespace: default
annotations:
bacula/backup.mode: clone
bacula/run.before.job.container.command: "*/sync -f /data1; sync -f /data2"
bacula/run.before.job.failjobonerror: "no"
bacula/backup.volumes: "pvc1,pvc2"
spec:
containers:
- image: ubuntu:latest
name: test-container
volumeMounts:
- name: pvc1
mountPath: /data1
- name: pvc2
mountPath: /data2
volumes:
- name: pvc1
persistentVolumeClaim:
claimName: pvc1
- name: pvc2
persistentVolumeClaim:
claimName: pvc2
In the example below, PostgreSQL’s data-file quiescing is used to ensure a consistent backup when using volume cloning.
Note
A complete PostgreSQL backup solution requires additional configuration and preparation. Those steps are omitted here for clarity.
The initial directive (run.before.job.container.command) prevents updates to
the database files, while the subsequent instruction
(run.after.snapshot.container.command) restores normal database functionality
once the PVC volume cloning process is completed.
apiVersion: v1
kind: Pod
metadata:
name: postgresql13
namespace: default
annotations:
bacula/backup.mode: standard
bacula/run.before.job.container.command: "*//bin/startpgsqlbackup.sh"
bacula/run.after.snapshot.container.command: "*//bin/stoppgsqlbackup.sh"
bacula/run.after.snapshot.failjobonerror: "yes"
bacula/backup.volumes: "pgsql"
spec:
containers:
- image: postgresql:13
name: postgresql-server
volumeMounts:
- name: pgsql
mountPath: /var/lib/pgsql
volumes:
- name: pgsql
persistentVolumeClaim:
claimName: pgsql-volume
In the following example, pvc1, is backed up using clone mode, while pvc2 is backed up using the standard backup method.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc2
annotations:
bacula/backup.mode: standard
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: app1
namespace: default
annotations:
bacula/backup.mode: clone
bacula/backup.volumes: "pvc1,pvc2"
spec:
containers:
- image: ubuntu:latest
name: test-container
volumeMounts:
- name: pvc1
mountPath: /data1
- name: pvc2
mountPath: /data2
volumes:
- name: pvc1
persistentVolumeClaim:
claimName: pvc1
- name: pvc2
persistentVolumeClaim:
claimName: pvc2
To ensure that a PVC is always backed up using a specific mode, specify the mode in the PVC annotations, for example:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-with-annotations
annotations:
bacula/backup.mode: clone
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
All PVCs defined with this storage class will perform backups using snapshots as per this storage definition.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-hostpath-sc
provisioner: hostpath.csi.k8s.io
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: plugintest-persistent-volume-claim-csi
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: csi-hostpath-sc
Go back to: Kubernetes Annotations.