Kubernetes Migration Strategies with Velero

Why Backup of kubernetes cluster is more important ?

Docker and Kubernetes gives so many conveniences out of the box like rolling deployments, high availability, restarting failed containers (aka self-healing), well-managed secrets, and the list goes on…Imagine the scenario where you have all system deployed on kubernetes only having 1000+ applications and your cluster is down for few hour due to any issues like network , hardware etc . Downtime of Kubernetes cluster may cause financial impact on business , also it will hurts your organization brand .Setting up entire cluster with all required application is not an easy task , it will require many hours , days to setup the cluster again and make ready in working condition . So we need to make sure that we will have some system ready which will help us to handle Kubernetes cluster disaster scenario quickly without any impact on business .

Here are some examples which you are listening almost each and every day while dealing with deployments on k8s :

  1. I didn’t have backup available of my application setup .
  2. What will i do if my cluster goes down ?
  3. What will i do if my namespace deleted ?
  4. How can I rollback my production deployment on previously deployed version ?

Well , Velero is answer for all above problems for maintaining your Kubernetes infrastructure to handle disaster scenario .Now let’s see what is velero and in which scenario we can use velero to solve stability issues of your kubernetes cluster .

Velero :

Velero is an open source tool to safely backup and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes , the most widely adopted tool and used in container orchestrator platform .Velero has support for private as well as public cloud systems such as EKS , AKS , GKE .

Official site : https://velero.io/

You can use velero in following cases :

  1. Restore application namespaces as it is on previous state from backup .
  2. Take backup of your Kubernetes clusters .
  3. You can use velero in kubernetes migration activity for migrating namespaces from one cluster to another .
  4. Its possible to update backup files and do customisation on it before restoring backup files on kubernetes cluster to create namespace from backup .
  5. You can also customize velero backup files before restoring it as per your need . Example : Kubernetes cluster upgrade where you need to update your kubernetes resources based on upgraded version , like upgrade from 1.15 to 1.18 .

Take a following scenario for migration use case .

Migrate application from cluster A to cluster B .

Here are the steps for setting up velero on kubernetes cluster :

prerequisite : You should have kubernetes cluster ready before starting with velero setup . You can verify your kubernetes setup by using “kubectl get nodes” for cluster A and cluster B .

Clone velero require setup files from github url :

git clone https://github.com/heptio/velero

curl -LO https://github.com/heptio/velero/releases/download/v1.1.0/velero-v1.1.0-linux-amd64.tar.gz

tar -C /usr/local/bin -xzvf velero-v1.1.0-linux-amd64.tar.gz

export PATH=$PATH:/usr/local/bin/velero-v1.1.0-linux-amd64/

  1. Setup minio on cluster A :

kubectl apply -f velero/examples/minio/00-minio-deployment.yaml

2. Setup Velero on cluster A :

create file “credentials-velero” with following details

[default]
aws_access_key_id = minio
aws_secret_access_key = minio123

Start Velero setup on cluster A :

velero install \
— provider aws \
— bucket velero \
— secret-file ./credentials-velero \
— use-volume-snapshots=false \
— backup-location-config region=minio,s3ForcePathStyle=”true”,s3Url=http://minio.velero.svc:9000

You can verify now velero commands :

velero get backup

Note : You can setup minio to access over nodeport or private domain can give details while setting up velero .

If you have exposed minio on private domain like “minio.test.com” , you can pass these details while creating velero setup .

Here is updated velero setup command :

velero install \
— provider aws \
— bucket velero \
— secret-file ./credentials-velero \
— use-volume-snapshots=false \
— backup-location-config region=minio,s3ForcePathStyle=”true”,s3Url=http://minio.test.com

3.Do velero setup for cluster B .

velero install \
— provider aws \
— bucket velero \
— secret-file ./credentials-velero \
— use-volume-snapshots=false \
— backup-location-config region=minio,s3ForcePathStyle=”true”,s3Url=http://minio.test.com

verify velero commands :

velero get backup

Cool , Your setup is ready now for both cluster . You can take backup , restore , migrate applications namespace from cluster A to cluster B now .

Here are some useful commands for velero :

1.Create backup for namespace

velero backup create <backup_file_bame> — include-namespaces <namespace_name>

2.List all created backup

velero get backup

3.Restore created backup .

velero restore create — from-backup <backup_file_name>

4. Describe backup details

velero describe backup $backup_name

5.Add cronjob to take latest backup automatically

velero create schedule backup-name — schedule=”*/30 * * * *” — include-namespaces <namespace_name >— ttl 48h0m0s

Advantages of using velero :

  • Take scheduled backups of your cluster and restore it in case of loss.
  • Migrate cluster resources to other clusters.
  • Replicate your production cluster to development and testing clusters.
  • Rollback deployments .
  • Manage & handle cluster disaster scenario in minutes .
  • You can define storage location to store backup files .
  • Its possible to take backup of stateful applications with velero .
Hope you like this blog….
Mahesh Wabale
Latest posts by Mahesh Wabale (see all)

Leave a Comment