Kubernetes backups with Velero
Velero backs up Kubernetes resources and persistent volumes to an S3 bucket and restores them into the same or another cluster. For chili, you use the velero-plugin-for-aws plugin with a custom endpoint. The full guide is in the Velero documentation and the AWS plugin documentation.
Prerequisites
- the Velero CLI and a Kubernetes cluster you can reach with
kubectl - Velero 1.18 with
velero-plugin-for-awsv1.14.0, or another combination from the plugin's compatibility table - a bucket, created in the chili Console, for example
velero-backup. Choose the templaterclone or scripts(Object Lock off, versioning on, accessRead, write and delete). - chili access keys (access key and secret key) of the IAM user for Velero
Connection values
Field | Value |
|---|---|
|
|
|
|
|
|
|
|
|
|
| optional, for example the cluster name |
Access key / secret key | in the credentials file |
1. Create the credentials file
Save the credentials in a file named credentials-velero:
[default]
aws_access_key_id = AKIA...
aws_secret_access_key = ...2. Install Velero
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.14.0 \
--bucket velero-backup \
--prefix cluster01 \
--secret-file ./credentials-velero \
--backup-location-config region=ch-east,s3ForcePathStyle="true",s3Url=https://s3-ch-east.chilistorage.com \
--use-volume-snapshots=false \
--use-node-agent--use-volume-snapshots=false turns off the AWS plugin's volume snapshots; they only work with Amazon EBS. With --use-node-agent, Velero installs the node agent for file-system backup of volumes.
If you created the bucket with georedundancy, use https://s3-ch.chilistorage.com as s3Url.
3. BackupStorageLocation as YAML
Instead of velero install, you can also manage the location as a resource, for example with GitOps:
apiVersion: velero.io/v1
kind: BackupStorageLocation
metadata:
name: default
namespace: velero
spec:
provider: aws
default: true
objectStorage:
bucket: velero-backup
prefix: cluster01
credential:
name: cloud-credentials
key: cloud
config:
region: ch-east
s3ForcePathStyle: "true"
s3Url: https://s3-ch-east.chilistorage.com4. Back up volumes with file-system backup
File-system backup copies the data of persistent volumes through the node agent and stores it with Kopia as a repository in the same bucket. You enable it per backup with --default-volumes-to-fs-backup or per pod with the annotation backup.velero.io/backup-volumes. Details are in the Velero file-system backup documentation.
5. Schedule and retention
velero schedule create daily \
--schedule="0 2 * * *" \
--default-volumes-to-fs-backup \
--ttl 720h0m0sAs a resource:
apiVersion: velero.io/v1
kind: Schedule
metadata:
name: daily
namespace: velero
spec:
schedule: "0 2 * * *"
template:
defaultVolumesToFsBackup: true
ttl: 720h0m0sWhen the ttl expires, Velero deletes the backup and its objects in the bucket.
Bucket without Object Lock
Velero does not set Object Lock retention and must delete expired backups itself. Technically, a bucket with Object Lock and Fixed period can be used: Velero's deletions then only set delete markers, and the locked versions stay until their retention ends. This has drawbacks. Locked versions continue to be billed, Velero no longer sees deleted backups and cannot restore them directly, and you have to recover older versions by hand when needed.
We therefore recommend a bucket without Object Lock and with versioning, as created by the rclone or scripts template. Versioning protects against accidental deletion without getting in Velero's way. Set up a lifecycle rule for noncurrent versions so deleted backups do not use storage indefinitely. The deletion key protects against the whole bucket being deleted. More on the options under Object Lock.
Verify
Check that the location is available and trigger a backup:
velero backup-location get
velero backup create test-backup --include-namespaces demo --default-volumes-to-fs-backup --wait
velero backup describe test-backup --detailsThen restore the backup into a new namespace and check the application:
velero restore create --from-backup test-backup --namespace-mappings demo:demo-restore --wait
velero restore getRestores cost nothing on chili, because there are no egress fees. This also applies to restores into another cluster.
Common pitfalls
- BackupStorageLocation stays `Unavailable`: check
s3Url,regionch-east,s3ForcePathStyle: "true"and the credentials file.kubectl logs deployment/velero -n veleroshows details. - Uploads fail with checksum errors: newer versions of the AWS plugin send a CRC32 checksum by default (
checksumAlgorithm). If uploads fail, setchecksumAlgorithm: ""in theconfigof the BackupStorageLocation. - Volumes missing from the backup: file-system backup is not active. Install Velero with
--use-node-agentand set--default-volumes-to-fs-backupor the pod annotation. - Old backups do not disappear from the bucket: the bucket was created with Object Lock or versioning and there is no lifecycle rule for noncurrent versions.
- Several clusters in one bucket: give each cluster its own
prefix, otherwise the clusters see each other's backups.