Backup Kubernetes Using Velero

Velero is an open source tool to safely backup and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes

source: Velero

There are many different ways in which you can backup your kubernetes cluster. The most basic one is to backup the etcd cluster and store it somewhere like amazon S3.

kubectl -n kube-system exec -it etcd-master — sh -c “ETCDCTL_API=3 \ ETCDCTL_CACERT=/etc/kubernetes/pki/etcd/ca.crt ETCDCTL_CERT=/etc/kubernetes/pki/etcd/server.crt \ ETCDCTL_KEY=/etc/kubernetes/pki/etcd/server.key etcdctl — endpoints= \ snapshot save /var/lib/etcd/snapshot.db “

However, you won’t be able to backup the etcd cluster of kubernetes services like EKS, AKS or GKE as there you don’t have access to kubernetes control plane. In that case we have to find alternate solution which can help us backup and restore any kubernetes services we you. Velero is one such tool that can help us achieve our goal.

  • Backup Kubernetes resources and persistent volumes for supported storage providers.
  • Restore Kubernetes resources and persistent volumes for supported storage providers.
  • When backing up persistent volumes w/o supported storage provider, Velero leverages restic as an agnostic solution to back up this sort of persistent volumes under some known limitations.
  • Backup whole Kubernetes cluster resources then restore if any Kubernetes resources loss.
  • Backup selected Kubernetes resources then restore if the selected Kubernetes resources loss.
  • Backup selected Kubernetes resources and persistent volumes then restore if the Kubernetes selected Kubernetes resources loss or data loss.
  • Replicate or migrate a cluster for any purpose, for example replicating a production cluster to a development cluster for testing.
  • A Velero server that runs on your Kubernetes cluster.
  • A restic deployed on each worker nodes that run on your Kubernetes cluster (optional).
  • A command-line client that runs locally (velero cli).
  1. Install Velero CLI: git release page —
$ wget
$ tar -xvf velero-v1.5.4-linux-amd64.tar.gz
$ mv velero-v1.5.4-linux-amd64/velero /usr/local/bin/
$ velero version

2. Create an amazon S3 bucket:

$ BUCKET=kubernetes-backup
$ REGION=us-east-2
$ aws s3api create-bucket \
--bucket $BUCKET \
--region $REGION \
--create-bucket-configuration LocationConstraint=$REGION

3. Install Velero Server using helm:

$ helm install velero vmware-tanzu/velero \
--namespace velero \
--create-namespace \
--set-file \
--set configuration.provider=aws \
--set \
--set configuration.backupStorageLocation.bucket=kubernetes-backup \
--set configuration.backupStorageLocation.config.region=us-east-2 \
--set snapshotsEnabled=false \
--set initContainers[0].name=velero-plugin-for-aws \
--set initContainers[0].image=velero/velero-plugin-for-aws:v1.2.0 \
--set initContainers[0].volumeMounts[0].mountPath=/target \
--set initContainers[0].volumeMounts[0].name=plugins \

4. Create a schedule backup of entire cluster:

$ velero schedule create backup-schedule-on-15-every-month --schedule="0 0 15 * *"

5. Restore your backup:

velero restore create <RESTORE_NAME> --from-backup <BACKUP_NAME>

I’m an undergrad student at IIIT Ranchi, pursuing my B-Tech in computer science and Engineering. I love to learn and share new technologies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store