Traditionally backup and restore is not well to use in containerized environment, they only tends to use for server protection. And our application is mostly running on k8s environment and its very important for us to have a backup in place.
There are number of tools available in market to backup our k8s cluster. Some of them are below:-
-
Cohesity
-
Kasten
-
OpenEBS
-
Portworx
-
Rancher Longhorn
- Velero
In this blog post, we will present options to backup/restore Kubernetes clusters running on ec2 instance with Velero and we will use S3 API based Object Store.
Velero is an open source tool for safely backing up and restoring resources in a Kubernetes cluster, performing disaster recovery, and migrating resources and persistent volumes to another Kubernetes cluster.
Velero offers key data protection features, such as scheduled backups, retention schedules, and pre- or post-backup hooks for custom actions. Velero can help protect data stored in persistent volumes and makes your entire Kubernetes cluster more resilient.
Velero Use Cases:-
Here are some of the things Velero can do:
-
Back up your cluster and restore it in case of loss.
-
Recover from disaster.
-
Copy cluster resources to other clusters.
-
Replicate your production environment to create development and testing environments.
-
Take a snapshot of your application’s state before upgrading a cluster
Velero consists of two main components:
-
A server that runs on your cluster
-
A command-line utility that runs locally
Velero supports plug-ins to enable it to work with different storage systems and Kubernetes platforms. You can run Velero in clusters on a cloud provider or on premises.
How Velero Works
-
Each Velero operation–on-demand backup, scheduled backup, restoration–is a custom resource that is defined with a Kubernetes custom resource definition, or CRD, and stored in
etcd
. -
Velero includes controllers that process the CRDs to back up and restore resources. You can back up or restore all objects in your cluster, or you can filter objects by type, namespace, or label.
Steps for setting up velero
Prerequisite
-
Make sure kubectl is installed on your machine
-
For storing your backups make sure you have storage account like AWS, Azure, GCP.
-
If AWS Storage is used then access and secret key required.
-
If Azure is used then subscription, azure storage account access key is in place.
Initial Setup:-
Step 1:
Create a S3 bucket
-
In our case bucket name is
velero001
and region is
ap-south-1
Step 2:
Create an IAM user with limited permission of S3 and save the access and secret key for next step
Step 3:
create a file in your directory
In my case , file name is
credentials-velero
Lets Start the installation process:-
Step 1:
Download the velero command line tool
curl -L -o /velero.tar.gz https://github.com/vmware-tanzu/velero/releases/download/v1.5.1/velero-v1.5.1-linux-amd64.tar.gz
tar -xvf /velero.tar.gz
mv /velero-v1.5.1-linux-amd64/velero /usr/local/bin
Step 2:
Check is the velero installed
velero version
Step 3:
Deploy Velero
lets Deploy Velero for AWS
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.2.0 \
--bucket \
--backup-location-config region= \
--snapshot-location-config region= \
--secret-file /credentials-velero
lets check
kubectl -n velero get pods
we can check the velero deployment logs with the below command
kubectl logs deployment/velero -n velero
If we want to backup whole cluster then we can use the below commandStep 4: Start Backup using velero
velero backup create
- If we want to take the back of a particular namespace then we can use the below comma
velero backup create --include-namespaces
- e.g:- In this example i am taking the backup of my namespace name test
velero backup create clouds --include-namespaces test
here the backup request is submitted successfully
now we can describe the backup to see is that the backup complete or fail
velero describe backup clouds
- If you want to see the backup go to your AWS S3 console and check the backups
- Setup backup with schedule
velero schedule create --schedule="*/5 * * * *" -- include-namespaces default
- Step 5: Restore the backups
velero restore create --from-backup
- If we want to take the restore cluster then we can use the below command
velero restore create demorestore --from-backup clouds
- If we want to take the restore a particular namespace then we can use the below command
velero restore create demorestore1 --from-backup clouds --include-namespaces test
- now we can describe the restore to see is that the restore complete or fail
velero restore describe demorestore1
Congratulations.... you follow all the steps and configure velero for backup and restore Kubernetes Cluster
References:-
https://velero.io/
https://github.com/vmware-tanzu/velero-plugin-for-aws