etcd-backup
by tjungbauer
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:
- Control-plane scheduling — the CronJob uses
nodeSelector: node-role.kubernetes.io/control-planeso the backup logic runs where etcd and the backup script live. - Host access — the pod uses
hostNetwork,hostPID, a hostPath mount of/, andsecurityContext.privileged: trueso it can reach the node filesystem under/hostand move files from/host/home/core/backup. oc debugon the local node — the container runsoc 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.- 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:
- Namespace: where will the cronjob be scheduled. (Default etcd-backup)
- ClusterRole: a dedicated Role that allows to get/list nodes and start a Debug pod.
- ServiceAccount: The ServiceAccount the CronJob will use (Default etcd-backup).
- ClusterRoleBinding: A binding that binds the ServiceAccount to the ClusterRole.
- ClusterRoleBinding-Privileged: A binding that binds the ServiceAccount to the SCC
system:openshift:scc:privileged(required for control-plane host access as described above). - PersistentVolumeClaim: The Claim to the Storage where the backup will be stored.
- Optional: PersistentVolume: A dedicated PV, used by the PVC. This is optional and might be automatically created, depending on the StorageClass.
- CronJob: The actual CronJob starts a Debug Pod to execute the backup script.
CronJob Workflow
The CronJob will perform the following:
- It will start a debug pod on one of the Control Planes (The CronJob is scheduled on one of the Control Planes).
- 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).
- Then a target folder might be created, if it does not exist yet using configured mountpath and the name of the cluster.
- 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.
- To save some space, the files will be zipped.
- 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:
| Repository | Name | Version |
|---|---|---|
| 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
| Name | Url | |
|---|---|---|
| tjungbauer | [email protected] | https://blog.stderr.at/ |
Sources
Source:
- https://github.com/tjungbauer/helm-charts
- https://charts.stderr.at/
- https://github.com/tjungbauer/openshift-clusterconfig-gitops
Source code: https://github.com/tjungbauer/helm-charts/tree/main/charts/etcd-backup
Parameters
Values
| Key | Type | Default | Description |
|---|---|---|---|
| backup_storage_size | string | "100Gi" | |
| clusterrolebindingPrivileged_name | string | etcd-backup-scc-privileged | Name of the PRIVILEGED cluster role binding |
| clusterrolebinding_name | string | "etcd-backup" | Name of the cluster role binding |
| clusterrolename | string | cluster-etcd-backup | Name of the cluster role |
| cronjob.image | string | registry.redhat.io/openshift4/ose-cli | Image to use for the CronJob |
| cronjob.mountpath | string | "/etcd-backup" | mount point inside the cronjob pod |
| cronjob.name | string | etcd-backup | Name of the CronJob |
| cronjob.retention | int | 30 | |
| cronjob.schedule | string | "0 */4 * * *" | Schedule of the Cronjob, for example: Every 4 hours |
| cronjobKeyPruner.enabled | bool | false | Enable Key Pruner CronJob. |
| cronjobKeyPruner.image | string | quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:2f47a31e743f4640016a795e317bd960b0480e0ce56f0cc5de15aa776eaa55b3 | Image for the cronjob |
| cronjobKeyPruner.name | string | key-pruner | Name of the CronJob |
| cronjobKeyPruner.retention | int | 30 | |
| cronjobKeyPruner.schedule | string | 55 */6 * * * | Schedule of the Cronjob, for example: Every 6 hours at minute 55 |
| enabled | bool | false | Enable ETCD backup. |
| name | string | "etcd-backup" | |
| namespace.create | bool | false | Create the Namespace? |
| namespace.description | string | "Openshift Backup Automation Tool" | Description of the Namespace |
| namespace.displayname | string | "Backup ETCD Automation" | DisplayName of the Namespace |
| namespace.name | string | etcd-backup | Name of the Namespace |
| pv.accessMode | string | ReadWriteOnce | Access mode of the PV |
| pv.enabled | bool | false | Enable PV creation? |
| pv.name | string | etcd-backup | Nmae of the PV |
| pv.path | string | "<path>" | Path of the NFS share for example |
| pv.server | string | "<ip-address>" | Server address of the NFS share for example |
| pv.size | string | 100Gi | Size of the Storage |
| pv.storageClass | string | "gp3-csi" | StorageClass must be provided as empty value here, since NFS mount is not provided as storageclass. |
| pvc.accessMode | string | ReadWriteOnce | using RWO accessMode, which is usually sufficient |
| pvc.name | string | etcd-backup | Name of the PVC |
| pvc.setVolumeName | bool | false | Set the name of the PV, only required if the PV will be created (see below) |
| pvc.size | string | 100Gi | Size of the Storage |
| pvc.storageClass | string | "gp3-csi" | StorageClass must be provided as empty value here, since NFS mount is not provided as storageclass. |
| pvc.volumeName | string | etcd-backup | Name of the PV |
| serviceAccount | string | etcd-backup | Name 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartetcd-backup is pinned at v1.0.14 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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