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.
Parts of the Kubernetes series
- Part1a: Install K8S with ansible
- Part1b: Install K8S with kubeadm
- Part1c: Install K8S with kubeadm and containerd
- Part1d: Install K8S with kubeadm and allow swap
- Part1e: Install K8S with kubeadm in HA mode
- Part2: Intall metal-lb with K8S
- Part2: Intall metal-lb with BGP
- Part3: Install Nginx ingress to K8S
- Part4: Install cert-manager to K8S
- Part5a: Use local persisten volume with K8S
- Part5b: Use ceph persisten volume with K8S
- Part5c: Use ceph CSI persisten volume with K8S
- Part5d: Kubernetes CephFS volume with CSI driver
- Part5e: Use Project Longhorn as persisten volume with K8S
- Part5f: Use OpenEBS as persisten volume with K8S
- Part5f: vSphere persistent storage for K8S
- Part6: Kubernetes volume expansion with Ceph RBD CSI driver
- Part7a: Install k8s with IPVS mode
- Part7b: Install k8s with IPVS mode
- Part8: Use Helm with K8S
- Part9: Tillerless helm2 install
- Part10: Kubernetes Dashboard SSO
- Part11: Kuberos for K8S
- Part12: Gangway for K8S
- Part13a: Velero Backup for K8S
- Part13b: How to Backup Kubernetes to git?
- Part14a: K8S Logging And Monitoring
- Part14b: Install Grafana Loki with Helm3
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