etcd-backup

by tjungbauer

Helm chartv1.0.14Apache-2.0Verified publisher

Create a CronJob that performs ETCD Backup and stores the backup to a PV.

About this chart

etcd-backup

Description

Create a CronJob that performs ETCD Backup and stores the backup to a PV.

This Helm Chart can be used to create a backup of ETCD. In addition, a key-pruner Cronjob can be enabled that will cleanup old secrets. It will execute a CronJob on one of the control planes in order to dump ETCD and store it to a PV.

WARNING: In order to create this backup, the CronJob must run a privileged pod on a control-plane node.

CAUTION: The backup contains two files: the etcd DB and a tar.gz. If etcd is encrypted, then the tar.gz will contain the keys to decrypt the DB. It is up to the storage team to be sure that the access to the share is secure. (Maybe in the future I can extend the Chart ... or just create a pull request :) )

Why privileged access and control-plane placement are required

OpenShift etcd backups are taken on the control plane, not from an ordinary application pod. The chart follows the approach documented by Red Hat: schedule work on a control-plane node and run /usr/local/bin/cluster-backup.sh in the host context via oc debug node/....

That workflow requires capabilities a restricted pod cannot have:

  1. Control-plane scheduling — the CronJob uses nodeSelector: node-role.kubernetes.io/control-plane so the backup logic runs where etcd and the backup script live.
  2. Host access — the pod uses hostNetwork, hostPID, a hostPath mount of /, and securityContext.privileged: true so it can reach the node filesystem under /host and move files from /host/home/core/backup.
  3. oc debug on the local node — the container runs oc debug node/<local-node> -- bash -c 'chroot /host sudo -E /usr/local/bin/cluster-backup.sh ...', which needs permission to start debug pods and execute commands in the control-plane host namespace.
  4. OpenShift SCC — item 5 below binds the ServiceAccount to system:openshift:scc:privileged. Without that SCC binding, the scheduler rejects the pod or the backup script cannot access the host paths it needs.

This is not optional hardening debt: a non-privileged, worker-node-only design cannot perform the supported control-plane etcd backup path. Treat the backup namespace, ServiceAccount, PVC, and privileged binding as highly sensitive infrastructure.

The following objects/settings will be created:

  1. Namespace: where will the cronjob be scheduled. (Default etcd-backup)
  2. ClusterRole: a dedicated Role that allows to get/list nodes and start a Debug pod.
  3. ServiceAccount: The ServiceAccount the CronJob will use (Default etcd-backup).
  4. ClusterRoleBinding: A binding that binds the ServiceAccount to the ClusterRole.
  5. ClusterRoleBinding-Privileged: A binding that binds the ServiceAccount to the SCC system:openshift:scc:privileged (required for control-plane host access as described above).
  6. PersistentVolumeClaim: The Claim to the Storage where the backup will be stored.
  7. Optional: PersistentVolume: A dedicated PV, used by the PVC. This is optional and might be automatically created, depending on the StorageClass.
  8. CronJob: The actual CronJob starts a Debug Pod to execute the backup script.

CronJob Workflow

The CronJob will perform the following:

  1. It will start a debug pod on one of the Control Planes (The CronJob is scheduled on one of the Control Planes).
  2. Via the Debug pod, on the Control Plane it will execute the script /usr/local/bin/cluster-backup.sh and store it into /home/core/backup (on the Control Plane).
  3. Then a target folder might be created, if it does not exist yet using configured mountpath and the name of the cluster.
  4. The backup files are moved from /host/home/core/backup/* (This is the backup location from the CronJob point of view) to the target folder.
  5. To save some space, the files will be zipped.
  6. Finally, backup files that are older than the retention time (default 30 days) will be removed from the target folder and from the Control Plane.

Verify the backup

The fole POD_ManualBackupCheck.yaml contains an example pod, that could be used to verify the backup. Per default, the backup is stored in the mounted PVC at etcd-backup. When you open a terminal to that Pod you can verify the backups:

sh-4.4# ls -la /etcd-backup/ocp/
total 73080
drwxrwxrwx. 2 root root     4096 Mar 17 05:50 .
drwxr-xr-x. 4 root root     4096 Mar 17 05:42 ..
-rw-------. 1 root root 24996317 Mar 17 05:48 snapshot_2024-03-17_054810.db.gz
-rw-------. 1 root root 24922192 Mar 17 05:49 snapshot_2024-03-17_054903.db.gz
-rw-------. 1 root root 24657038 Mar 17 05:50 snapshot_2024-03-17_055004.db.gz
-rw-------. 1 root root    78022 Mar 17 05:48 static_kuberesources_2024-03-17_054810.tar.gz
-rw-------. 1 root root    78022 Mar 17 05:49 static_kuberesources_2024-03-17_054903.tar.gz
-rw-------. 1 root root    78022 Mar 17 05:50 static_kuberesources_2024-03-17_055004.tar.gz

CAUTION: The backup contains two files: the etcd DB and a tar.gz. If etcd is encrypted, then the tar.gz will contain the keys to decrypt the DB. It is up to the storage team to be sure that the access to the share is secure.

Dependencies

This chart has the following dependencies:

RepositoryNameVersion
https://charts.stderr.at/tpl~1.0.31

This chart has no dependencies on other charts.

It is best used with a full GitOps approach such as Argo CD does. For example, https://github.com/tjungbauer/openshift-clusterconfig-gitops (folder clusters/all/etcd-backup)

Maintainers

NameEmailUrl
tjungbauer[email protected]https://blog.stderr.at/

Sources

Source:

Source code: https://github.com/tjungbauer/helm-charts/tree/main/charts/etcd-backup

Parameters

Values

KeyTypeDefaultDescription
backup_storage_sizestring"100Gi"
clusterrolebindingPrivileged_namestringetcd-backup-scc-privilegedName of the PRIVILEGED cluster role binding
clusterrolebinding_namestring"etcd-backup"Name of the cluster role binding
clusterrolenamestringcluster-etcd-backupName of the cluster role
cronjob.imagestringregistry.redhat.io/openshift4/ose-cliImage to use for the CronJob
cronjob.mountpathstring"/etcd-backup"mount point inside the cronjob pod
cronjob.namestringetcd-backupName of the CronJob
cronjob.retentionint30
cronjob.schedulestring"0 */4 * * *"Schedule of the Cronjob, for example: Every 4 hours
cronjobKeyPruner.enabledboolfalseEnable Key Pruner CronJob.
cronjobKeyPruner.imagestringquay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:2f47a31e743f4640016a795e317bd960b0480e0ce56f0cc5de15aa776eaa55b3Image for the cronjob
cronjobKeyPruner.namestringkey-prunerName of the CronJob
cronjobKeyPruner.retentionint30
cronjobKeyPruner.schedulestring55 */6 * * *Schedule of the Cronjob, for example: Every 6 hours at minute 55
enabledboolfalseEnable ETCD backup.
namestring"etcd-backup"
namespace.createboolfalseCreate the Namespace?
namespace.descriptionstring"Openshift Backup Automation Tool"Description of the Namespace
namespace.displaynamestring"Backup ETCD Automation"DisplayName of the Namespace
namespace.namestringetcd-backupName of the Namespace
pv.accessModestringReadWriteOnceAccess mode of the PV
pv.enabledboolfalseEnable PV creation?
pv.namestringetcd-backupNmae of the PV
pv.pathstring"<path>"Path of the NFS share for example
pv.serverstring"<ip-address>"Server address of the NFS share for example
pv.sizestring100GiSize of the Storage
pv.storageClassstring"gp3-csi"StorageClass must be provided as empty value here, since NFS mount is not provided as storageclass.
pvc.accessModestringReadWriteOnceusing RWO accessMode, which is usually sufficient
pvc.namestringetcd-backupName of the PVC
pvc.setVolumeNameboolfalseSet the name of the PV, only required if the PV will be created (see below)
pvc.sizestring100GiSize of the Storage
pvc.storageClassstring"gp3-csi"StorageClass must be provided as empty value here, since NFS mount is not provided as storageclass.
pvc.volumeNamestringetcd-backupName of the PV
serviceAccountstringetcd-backupName of the ServiceAccount

Example values

---
name: &bu_name etcd-backup
backup_storage_size: &backup_storage_size "100Gi"

enabled: true
clusterrolebinding_name: *bu_name

# Variables for the Namespace where ETCD backup shall be executed.
namespace:
  create: true
  name: *bu_name
  displayname: "Backup ETCD Automation"
  description: "Openshift Backup Automation Tool"
serviceAccount: *bu_name

cronjob:
  name: *bu_name
  # Every 4 hours
  schedule: "0 */4 * * *"
  # How long shall I keep the backups
  retention: 30
  # mount point inside the cronjob pod
  mountpath: /etcd-backup

pvc:
  name: *bu_name
  # using RWO accessMode, which is usually sufficient
  accessMode: "ReadWriteOnce"
  size: *backup_storage_size
  # If not StorageClass is provided (might be because NFS and the PV must be created first, then still use this parameter as storageClass: ""
  storageClass: "gp3-csi"
  # name of the PV
  setVolumeName: false
  volumeName: *bu_name

Installing the Chart

To install the chart with the release name my-release:

helm install my-release tjungbauer/<chart-name>>

The command deploys the chart on the Kubernetes cluster in the default configuration.

Uninstalling the Chart

To uninstall/delete the my-release deployment:

helm delete my-release

The command removes all the Kubernetes components associated with the chart and deletes the release.


Autogenerated from chart metadata using helm-docs v1.14.2

Deploy etcd-backup with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has etcd-backup on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartetcd-backup is pinned at v1.0.14 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply