How to Install Velero for Kubernetes Clusters Backup

Written By

Florian Pialoux

Blog

Modern-day applications are built within containers such as Docker for portability and ease of deployment. These containers are further managed by container orchestration platforms such as Kubernetes. In short, Kubernetes clusters host all critical aspects of an application, including the codebase, databases, and any relevant APIs.

Having a backup of the application cluster is a key part of the disaster protection protocol. It allows Developers to create copies of the application and recover the codebase in case it gets lost or deleted. 

Velero is an open-source backup software that allows Developers to backup namespaces, persistent storage, or entire Kubernetes clusters to a storage object.

This article offers an in-depth guide on how to install Velero to back up your Kubernetes clusters. 

Table of Contents

Why Back up a Kubernetes Cluster?

Kubernetes Cluster backups are essential for recovery during disaster scenarios such as server failures, damage to physical infrastructure, or data encryption from a malware attack. 

Essentially, it means having a backup of your entire application, which can prove critical in the event of scenarios such as the ones mentioned above since they often result in operational disruptions,  business loss, and possible lawsuits in case of data loss. 

Consequently, a properly backed-up Kubernetes cluster can help resume operations with little effort and keep all data assets safe by storing multiple copies.

Kubernetes cluster backups also allow multiple versions of applications to be created and migrated to different environments. These versions are used for different purposes, such as Testing, Development, and Deployment.

Velero logo icon

What Is Velero?

Velero is a popular open-source backup software maintained by VMWare used for the backup and restoration of Kubernetes clusters. It offers impressive features and a large community for Development and support, making it popular among Kubernetes users. Typically, this open-source tool offers connectivity with various storage options for easy backup and versioning of the Kubernetes cluster. 

Velero’s Key Features for Kubernetes Cluster Backup

  • Selective Backup: Users can choose to back up entire clusters or specific namespaces depending on their requirements.
  • Schedule Backups: It allows users to set up schedules for backups. This ensures the application is periodically backed up with all the latest changes.
  • Snapshot Volumes: It supports taking snapshots of the underlying data stored in persistent volumes, which is crucial for preserving stateful applications.
  • Custom Actions: Users can set custom actions to be triggered pre or post-backup. They can take snapshots before creating a backup or pause an application if required.

Velero offers great functionality and features, all the while being free to use, which explains why it’s a popular choice in the Kubernetes ecosystem over most cluster backup tools.

Kubernetes Cluster Backup With Velero

How to Install Velero

Let’s now take a brief look at how you can install Velero to create backups for your Kubernetes clusters. The overall procedure and commands vary according to the requirement and available resources. 

This tutorial will provide a general overview of backing up a cluster on the AWS S3 Bucket and restoration during a disaster event.

Prerequisites

Before diving into the commands, Velero requires the following environments to be accessible.

  • A server with the Kubernetes cluster (v1.16 or later, as per present documentation) with container networking enabled. This is the environment where Velero will execute its commands.
  • An object storage backup environment where the cluster backup will be stored. The environment must be from the list of supported providers. Velero will connect to this environment and store the cluster snapshots and backup files.

Additionally, kubectl must also be installed on your local system to execute CLI commands. Once all prerequisites are complete, the next step is to install Velero

Install Velero (Local)

First, install Velero on your local system. This can be done in multiple ways, depending on your system.

For MacOS, run the following command in the terminal.

   
      brew install velero
   

For Linux, you will have to download the GitHub Release. The latest release can be downloaded from here, and the binary should be moved to the default environment $PATH.

Once the steps are done, the installation can be confirmed via the following command.

   
      velero version  client-only
   

Install Velero (Cluster)

Next, you need to install Velero on the server where the Kubernetes cluster is present. The installation command will vary depending on the Kubernetes environments and the storage provider. Refer to the documentation for specific usecases.

Use these command for AWS S3 bucket storage:

   
      velero install \
    --provider aws \
    --bucket $BUCKET \
    --secret-file ./credentials-velero \
    --backup-location-config region=$REGION \
    --snapshot-location-config region=$REGION
   

Remember to add the appropriate bucket name and region in the command before executing. 

Create Backup

Once the installation is complete, you can create the cluster backups with the commands listed below. Once again, it is important to note that these commands might vary depending on different environments. It is advisable to research the commands from the official documentation.

For the entire Kubernetes object:

   
      velero backup create backup-name
   

This command will backup a snapshot of the Kubernetes cluster to the S3 bucket attached. You can also choose to schedule backups for the cluster or named namespaces. This involves defining the schedule using the following command:

   
      Velero schedule create example-schedule --schedule="0 3 * * *"
   

The schedule is defined using a cron-like format and is used to create backups with the following command:

   
      velero backup create --from-schedule example-schedule
   

Restore Backup:

To view all created backups, run the following command;

   
      velero backup get
   

To restore any of the backups, run:

   
      velero restore create --from-backup backup-name
   

Conclusion

Velero is an open-source backup software that allows users to back up their Kubernetes clusters. These clusters host the entire application code base and databases and are critical for business operations. 

Creating a backup of the clusters is essential to not only ensure application recovery during disaster situations but also to resume business operations.

Velero is a popular utility within the Kubernetes community thanks to its open-source nature and features like backup schedules and support for various object storage hosts. 

Furthermore, the backup procedure is simple and can be completed with a few commands. Primarily, It requires you to install Velero on your local system and the cluster server. What follows is running the provider-specific Velero command on the local system to back up the Kubernetes cluster to the attached storage object, such as AWS. 

Similarly, the backup can be restored with a single command by simply providing the backup name.

You may also be interested in:

Software Testing: Top 5 Best Practices

Google Cloud Cost Optimization Best Practices

On-Premise to Cloud Migration: 5 Key Benefits for Businesses

MLOps vs DevOps: The Key Similarities and Differences

AWS EKS Monitoring with Prometheus and Grafana

How to Manage Code Quality with SonarQube and GitHub Actions

Bluelight Consulting is a nearshore DevOps & Software Outsourcing company that helps startups, SaaS, and enterprises with cutting-edge solutions.

More cost-effective than hiring in-house, with Nearshore Boost, our nearshore software development service, you can ensure your business stays competitive with an expanded team and a bigger global presence, you can be flexible as you respond to your customers’ needs.

Learn more about our services by booking a free consultation with us today!

Let us solve your business’ biggest challenges

Book a free Consultation
Save 50+ hours of project time per developer on interviewing.
Tell us the skills you need and we'll find the best developer for your needs in days, not weeks.

Discuss your project with us today!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.