Kubernetes, as we know, coordinates a highly available cluster of computers that are connected to work as a single unit. Kubernetes contains a number of abstractions that allows deployment of containerized applications to the cluster without attaching them to individual machines.
In short, Kubernetes is –
In this post, we are going to take look at steps on how to back up and restore your Kubernetes cluster resources and persistent volumes using Velero open-source tool.
Quick Snapshot
First off, let’s understand the typical scenarios where you would need to use backup
Now that we are clear on why backup is needed, we can list out objects to back up in the next section.
Velero (formerly Heptio Ark) gives you tools to back up and restore your Kubernetes cluster resources and persistent volumes. Velero consists of:
Each Velero operation, for example, on-demand backup, scheduled backup, restore, etc., is a custom resource, defined with a Kubernetes Custom Resource Definition (CRD) and stored in etcd store.
When you run command velero backup create test-backup
:
Backup
object.BackupController
looks the new Backup
object and performs validation.BackupController
begins the backup operation. It collects the data to back up by querying the API server for resources.BackupController
makes a call to the object storage service e.g., AWS S3 to upload the backup file.In the next section,we will take look at steps on how to back up and restore your Kubernetes cluster resources and persistent volumes.
Following are the prerequisites that are required for this quick start
Before the installation, let us check if we have got the right Kubernetes version.
Download the latest release of Velero with the below command:
curl -LO https://get.helm.sh/helm-v3.0.0-linux-amd64.tar.gz
I’m using Linux, for other platforms, see the releases page. Untar the download file and move the velero executable to /usr/local/bin
or your path.
Create a Velero-specific credentials file (credentials-velero
) in your local directory:
echo "[default]
aws_access_key_id = minio
aws_secret_access_key = minio123" > credentials-velero
Velero needs appropriate storage providers to store backup and snapshot data, For this demo, we are going to use Minio, an S3-compatible storage service that runs locally on the cluster. The above credentials would be used by Minio instance. Refer list of Supported storage providers.
Now that we have credentials and cluster ready, we can install the Velero server.
In the below steps, we would be starting the server and the local storage service. In the Velero folder run the below commands:
Configure local storage service using below command:
kubectl apply -f examples/minio/00-minio-deployment.yaml
Start Velero server by using below 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.velero.svc:9000
For now, we are assuming Velero is running within a local cluster without a volume provider capable of snapshots.
Check if Velero deployments are successfully created.
Next step is to deploy sample nginx
application on the cluster with the following command:
kubectl apply -f velero/examples/nginx-app/base.yaml
Check if Sample application deployments are successfully created.
Now we will be creating a backup for any object that matches the app=nginx
label selector:
velero backup create nginx-backup --selector app=nginx
If you want to backup all objects except those matching thethen you can use 'backup notin (ignore)'
option.
There are also options for creating scheduled backups based on a cron expression.
To verify if the backup has completed, use describe command as below:
velero backup describe nginx-backup
We now have backup operation completed, to test restore operation, we will be deleting the namespace.
Verify if Nginx service and deployment are deleted:
It usually takes few minutes for the namespace to be fully cleaned up.
To list the backups we have created, use the below command:
velero restore get
To restore the backup we have created, use the below command:
velero restore create --from-backup nginx-backup
After the restore finishes, you can check if the restored deployments back in namespace:
If there are errors or warnings during the restore operation, you can use the below command to check the details:
velero restore describe <RESTORE_NAME>
Congrats! we have successfully made backup and restore them.
If for some limitations, you’re not able to use Velero then you can always use Kubectl
CLI to export resource definitions from your existing Kubernetes cluster and then apply them to your target cluster. Following is the command to export objects.
kubectl get deployment -o=yaml --export > deployments.yaml
Below are known limitations of Velero
BackupStorageLocation
, and one VolumeSnapshotLocation
per volume provider. It is not possible to send a single Velero backup to multiple backup storage locations simultaneously, or a single volume snapshot to multiple locations simultaneously.Like this post? Don’t forget to share it!
62% of UX designers now use AI to enhance their workflows. Artificial intelligence (AI) rapidly…
The integration of artificial intelligence into graphic design through tools like Adobe Photoshop can save…
The cryptocurrency trading world has grown significantly in recent years, with automation playing a key…
The non-fungible token (NFT) market has witnessed explosive growth over the past few years, transforming…
There are few things as valuable to a business as well-designed software. Organizations today rely…
The cryptocurrency industry is being reshaped by the fusion of blockchain technology and artificial intelligence…
This website uses cookies.