Backing up and Restoring kubernetes cluster with Velero
Why is backup of the kubernetes cluster more important?
Docker and Kubernetes are the modern-day runtime environments and 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 this scenario
Where you have 100+ microservices deployed and running then your cluster goes down for a few hours due to any issues like network, hardware etc. Downtime of kubernetes clusters may cause financial impact on your business, affect your brand image, data loss or even interfere with your SLA uptime contracts. All in all system downtime can seriously impact your company’s operations both in the short term and long.
Have you ever thought what if?
- You accidentally delete a namespace?
- You didn’t have backup of your application setup?
- Your cluster goes down?
- How to rollback your production deployment to a previously available stable release?
Well, Velero is the solution for all the above problems listed for maintaining your kubernetes infrastructure to handle a disaster scenario.
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 .
- Take backups of your cluster and restore them in case of loss.
- Bring back namespaces or any lost k8s resources
- Enabling cluster portability by easily migrating Kubernetes resources from one cluster to another
- Replicate your production cluster to development and testing clusters.
Steps for setting up Velero on your cluster
- Access to a kubernetes cluster with kubectl installed locally
- First you need to install the Velero CLI on your system this can be done easily via homebrew or if you are on a linux machine or windows you can fetch a latest version of the CLI from here: https://github.com/vmware-tanzu/velero/releases/tag/v1.6.0
- Make a credentials file for velero so that it can access the storage let’s say in our case it’s AWS S3 bucket. We create a file with these credentials:
A Velero installation consists of Kubernetes objects that all work together to create, schedule, and manage backups. The velero executable that you just downloaded can generate and install these objects for you. The velero install command will perform the preliminary set-up steps to get your cluster ready for backups. Specifically, it will:
- Create a velero Namespace.
- Add the velero Service Account.
- Configure role-based access control (RBAC) rules to grant permissions to the velero Service Account.
- Install Custom Resource Definitions (CRDs) for the Velero-specific resources: Backup, Schedule, Restore, Config.
- Register Velero Plugins to manage Block snapshots and Spaces storage.
Backup the deployed app
The output should be something like this:
This output indicates that nginx-backup completed successfully. The list of resources shows each of the Kubernetes objects that was included in the backup. The final section shows the PersistentVolume was also backed up using a filesystem snapshot.
We can now test the restore procedure.
- Delete the namespace and do kubectl get deployments nothing should return.
Now when our app is no longer available, we should do a restore to check if we can get it back simply run this command.
Now if you get your service using kubectl it should be there. Kudos!
In this guide we installed and configured the Velero Kubernetes backup tool on a cluster.
Velero can also be used to schedule regular backups of your Kubernetes cluster for disaster recovery. To do this, you can use the velero schedule command. Velero can also be used to migrate resources from one cluster to another.
It also has a very good documentation on their official website velero.io you can visit there and check out more features which can be implemented.
Get In Touch
How Can We Help ?
We make your product happen. Our dynamic, robust and scalable solutions help you drive value at the greatest speed in the market