Backup your Kubernetes Cluster with Velero

Velero (formerly Heptio Ark) gives you tools to back up and restore your Kubernetes cluster resources and persistent volumes. You can run Velero with a cloud provider or on-premises.

Parst of the Kubernetes series

How it’s work

Each Velero operation (on-demand backup, scheduled backup, restore) is a custom resource, stored in etcd. A backup opertaion is uploads a tarball of copied Kubernetes objects into cloud object storage. After that calls the cloud provider API to make disk snapshots of persistent volumes, if specified. Optionally you can specify hooks to be executed during the backup. When you create a backup, you can specify a TTL by adding the flag --ttl <DURATION>.

Velero supported providers

Object Store Volume Snapshotter
AWS S3 AWS EBS
Google Cloud Storage Google Compute Engine Disks
Azure Blob Storage Azure Managed Disks
- Portworx Volume
- OpenEBS CStor Volume

Install cli

wget https://github.com/vmware-tanzu/velero/releases/download/v1.2.0/velero-v1.2.0-linux-amd64.tar.gz
tar -xzf velero-v1.2.0-linux-amd64.tar.gz
sudo cp velero-v1.2.0-linux-amd64/velero /usr/local/sbin

Deploy minio and deno app

kubctl apply -f velero-v1.2.0-linux-amd64/examples/minio/00-minio-deployment.yaml
kubctl apply -f velero-v1.2.0-linux-amd64/examples/nginx-app/base.yaml

Deploy server component

nano velero.yaml
image:
  repository: velero/velero
  tag: v1.2.0
  pullPolicy: IfNotPresent

initContainers:
  - name: aws
    image: velero/velero-plugin-for-aws:v1.0.0
    imagePullPolicy: IfNotPresent
    volumeMounts:
      - mountPath: /target
        name: plugins

metrics:
  enabled: true
  scrapeInterval: 30s

  # Pod annotations for Prometheus
  podAnnotations:
    prometheus.io/scrape: "true"
    prometheus.io/port: "8085"
    prometheus.io/path: "/metrics"

  serviceMonitor:
    enabled: false
    additionalLabels: {}



configuration:
  provider: aws
  backupStorageLocation:
    name: aws
    bucket: velero
    config:
      region: minio
      s3ForcePathStyle: true
      publicUrl: https://minio.devopstales.intra
      s3Url: http://minio:9000
  volumeSnapshotLocation:
    name: aws
    bucket: kubernetes-pv
    config:
      region: minio
      s3ForcePathStyle: true
      publicUrl: https://minio.devopstales.intra
      s3Url: http://minio:9000

credentials:
  useSecret: true
  secretContents:
    cloud: |
      [default]
      aws_access_key_id = minio
      aws_secret_access_key = minio123

snapshotsEnabled: true
deployRestic: true
helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts
helm repo update

helm install velero vmware-tanzu/velero --namespace velero -f velero.yaml

Create Backup

velero backup create nginx-backup --selector app=nginx
velero backup describe nginx-backup
velero backup logs nginx-backup
velero backup get

velero schedule create nginx-daily --schedule="0 1 * * *" --selector app=nginx
velero schedule get
velero backup get

Restore test

kubectl delete ns nginx-example

velero restore create --from-backup nginx-backup
velero restore get

kubectl get po -n nginx-example