DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Backup and Disaster Recovery in the Age of GitOps and CI/CD Deployments
  • The Production-Ready Kubernetes Service Checklist
  • 10 Best Practices for Managing Kubernetes at Scale
  • Optimizing Prometheus Queries With PromQL

Trending

  • A Guide to Container Runtimes
  • Create Your Own AI-Powered Virtual Tutor: An Easy Tutorial
  • The Modern Data Stack Is Overrated — Here’s What Works
  • Unlocking AI Coding Assistants Part 2: Generating Code
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Kubernetes Cluster Backups With Velero

Kubernetes Cluster Backups With Velero

Kubernetes cluster disaster recovery with open-source backup and restoration tool

By 
Tetiana Fydorenchyk user avatar
Tetiana Fydorenchyk
·
Updated Jul. 11, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
6.3K Views

Join the DZone community and get the full member experience.

Join For Free

Velero is an open-source backup and restoration tool for Kubernetes cluster disaster recovery. It also supports the migration of cluster resources and persistent volumes backup. Manual or scheduled backups to the external storage ensure your data safety and protection.

You can leverage Velero to achieve the following tasks:

  • Back up your Kubernetes cluster or selected resources / persistent volumes and restore in case of cluster data loss.
  • Replicate a whole Kubernetes cluster (e.g. create a development/testing instance based on the production one) or migrate selected resources to other clusters.

You can easily integrate Velero backups with the Kubernetes cluster on the Virtuozzo Application Platform. Just follow the simple steps below:

1. Start by organizing the S3-compatible storage, which Velero will use to store your backups. For example, you can use AWS S3, VHI S3, or MinIO cluster.

In our guide, we’ll proceed with the latter option so that you can have the whole setup under the same platform. You can install the MinIO Cluster at Virtuozzo Application Platform in a few clicks using the Marketplace (follow the steps in the linked guide).

After the installation, you’ll see your MinIO installation credentials (also sent via email). You’ll need this data later on:

Waiting for the first server to format the disks.

2. Connect to the admin panel of your MinIO cluster and create a new bucket (e.g. velero) in the storage cluster.

3. Find the latest vmware-tanzu/velero release (v1.8.1 in our case), click the link in the Download section and copy the URL to the linux amd64 archive.

Tip: In our example, we’ll upload the velero binary to the Kubernetes Cluster server directly. However, you can keep it anywhere (e.g. locally) with the API access to the cluster.

4. Connect to your Kubernetes Cluster control plane via SSH (e.g. Web SSH). Download the archive using the link from the previous step and extract the velero binary to the /usr/local/sbin directory.

Shell
 
wget https://github.com/vmware-tanzu/velero/releases/download/v1.8.1/velero-v1.8.1-linux-amd64.tar.gz
tar -zxvf velero-v1.8.1-linux-amd64.tar.gz -C /usr/local/sbin --strip-components=1 velero-v1.8.1-linux-amd64/velero


Note: If uploading via the file manager, you’ll need to adjust the file permissions:

Shell
 
chmod 755 /usr/local/sbin/velero

5. Create the /root/credentials-velero file and put the S3 storage credential (see the first step):

Properties files
 
[default]
aws_access_key_id = {accessKey}
aws_secret_access_key = {secretKey}


6. Adjust the command below by providing the correct values and execute it to deploy Velero. The following placeholders need adjustment:

  • {bucket} - a name of the bucket (velero in our case, see the second step)
  • {s3Url} - an http:// link to your S3 storage (http://minio.vip.jelastic.cloud/ in our case, see the first step)
  • {image} - a velero container image (velero/velero:v1.8.1 in our case, see the third step)
Shell
 
velero install --provider aws --plugins velero/velero-plugin-for-aws:v1.4.1 --bucket {bucket} --secret-file ./credentials-velero --use-volume-snapshots=true  --backup-location-config region=default,s3ForcePathStyle="true",s3Url={s3Url} --image {image} --snapshot-location-config region="default" --use-restic


We use AWS emulation to work with S3 and restic add-on since we have NFS storage for which we don’t have a native snapshot functionality.

7. Let’s deploy a test application with storage and mounts to test how Velero can perform backups. We’ll use the following example application:

Shell
 
wget https://www.virtuozzo.com/application-platform-docs/kubernetes-velero-backups/test-instance.yaml
kubectl apply -f test-instance.yaml


You can check the application with the following command:

Shell
 
kubectl get pods,pvc,pv -n test-nginx


Execute the commands listed below to generate some random data that will emulate application usage.

Shell
 
kubectl -n test-nginx exec -it nginx-test -- /bin/bash
dd if=/dev/urandom of=/usr/share/nginx/html/test-file3.txt count=512000 bs=1024
ls -laSh /usr/share/nginx/html/
exit


8. You need to annotate your application pods to ensure the NFS storage data is included in the backup. You can get the required storage name from the deployed application (mystorage in our case).

Note: Without the annotation, PV and PVC definitions are copied but not the data.

Shell
 
kubectl -n test-nginx annotate pod/nginx-test backup.velero.io/backup-volumes=mystorage


9. Now, let’s create a backup of your test application:

Shell
 
velero backup create test-nginx-b4 --include-namespaces test-nginx --wait


10. Check your MinIO storage. The data from Velero and restic should be present.

Also, check that the created backup exists and is fine.

Shell
 
velero get backups


11. Let’s completely remove the example application to test the restoration process properly.

Shell
 
kubectl delete ns test-nginx


Clean up the Shared Storage data (in the /data directory) as well.

12. Once ready, restore your application from the backup with the following command:

Shell
 
velero restore create --from-backup test-nginx-b4


That’s it! You can verify that everything, including stored data, is restored.

Backup Scheduling

Velero supports backup process automation through scheduling. You can create the required schedule template via cron notation (using the UTC timezone). The general syntax is the following:

Shell
 
velero schedule create {scheduleName} --schedule="{schedule}"

1. Use the table below as a reference to set the required schedule using a standard cron expression:

Character Position Character Period Acceptable Values
1 Minute 0-59,*
2 Hour 0-23,*
3 Day of Month 1-31,*
4 Month 1-12,*
5 Day of Week 0-7,*


For example, to create a backup every six hours:

Shell
 
velero schedule create myschedule --schedule="0 */6 * * *"

2. The schedule can also be expressed using the @every {duration} syntax. The duration can be specified using a combination of seconds (s), minutes (m), and hours (h).

For example, to create a backup every six hours:

Shell
 
velero schedule create myschedule --schedule="@every 6h"

3. You can add additional scheduling options (to back up a specific namespace, set a backup's lifetime, etc.) via dedicated parameters. Use the help flag to view the complete list of parameters:

Shell
 
velero schedule create --help

Congratulations! Now you know how to automatically back up your Kubernetes projects with Velero.

Backup Kubernetes cluster

Opinions expressed by DZone contributors are their own.

Related

  • Backup and Disaster Recovery in the Age of GitOps and CI/CD Deployments
  • The Production-Ready Kubernetes Service Checklist
  • 10 Best Practices for Managing Kubernetes at Scale
  • Optimizing Prometheus Queries With PromQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!