Velero: EKS backup and restore || Cluster Migration

30 / Sep / 2023 by Sumit Tiwari 0 comments

Backup Kubernetes PV with Velero: The new approach

Overview

Velero (formerly Heptio Ark) gives you tools to back up and restore your Kubernetes cluster resources and persistent volumes. You can run Velero with a cloud provider or on-premises.

Velero lets you:

  • Take backups of your cluster and restore them in case of loss.
  • Migrate cluster resources to other clusters.
  • Replicate your production cluster to development and testing clusters.

Velero consists of:

  • A server that runs on your cluster
  • A command-line client that runs locally

Pre-requisite links

  • HomeBrew links: https://docs.brew.sh/Installation
  • Chocolatey links: https://chocolatey.org/install
  • KUBECTL setup: https://formulae.brew.sh/formula/kubernetes-cli || https://pwittrock.github.io/docs/tasks/tools/install-kubectl/ || https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html || https://kubernetes.io/docs/tasks/tools/
  • AWS CLI setup: https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html
  • EKSCTL setup: https://eksctl.io/ || https://formulae.brew.sh/formula/eksctl

Create AWS EKS cluster

  • Create EKS cluster on AWS
eksctl create cluster - name eks-primary-cluster - node-type t2.large - nodes 1 - nodes-min 1 - nodes-max 2 - region us-east-1 - zones=us-east-1a,us-east-1b,us-east-1c
  • Get EKS Cluster service
eksctl get cluster - name eks-primary-cluster - region us-east-1
  • Update kubeconfig file
aws eks update-kubeconfig - name eks-primary-cluster
  • Get EKS Pod data.
kubectl get pods - all-namespaces
  • Delete EKS cluster
eksctl delete cluster - name <cluster-name> - region <region>

Create AWS EKS Backup & Restore

Step1: CREATE S3 BUCKET

aws s3api create-bucket - bucket <bucket-name> - region <region>

Step 2. INSTALL VELERO CLIENT

  • USING chocolatey
choco install velero
  • USING brew
brew install velero

Step 3. Install Velero on EKS

  • Window:
velero install - provider aws - plugins velero/velero-plugin-for-aws:v1.0.1 - bucket <bucket-name> - backup-location-config region=<region> - snapshot-location-config region=<region> - secret-file C:\Users\Lenovo\.aws\credentials
  • Linux/MacOS:
velero install - provider aws - plugins velero/velero-plugin-for-aws:v1.0.1 - bucket <bucket-name> - backup-location-config region=<region> - snapshot-location-config region=<region> - secret-file ~/.aws/credentials

Step 4. Check the installation

kubectl get all -n velero

Step 5. DEPLOY TEST APPLICATION

kubectl create namespace <namespace-name>

kubectl create deployment web - image=gcr.io/google-samples/hello-app:1.0 -n <namespace-name>

kubectl create deployment nginx - image=nginx -n <namespace-name>

Step 6. VERIFY DEPLOYMENT

kubectl get deployments -n <namespace-name>

Step 7. BACKUP AND RESTORE

velero backup create <backupname> - include-namespaces <namespace-name>

Step 8. DESCRIBE BACKUP

velero backup describe <backup-name>

Step 9. DELETE ABOVE DEPLOYMENT

kubectl delete ns <namespace-name>

Step 10. RESTORE BACKUP ON THE SAME CLUSTER.

velero restore create - from-backup <backup-name>

Step 11. RESTORE ON THE OTHER EKS CLUSTER

Install the velero on both clusters but make sure that cluster points to the same S3 bucket
  • Window:
velero install - provider aws - plugins velero/velero-plugin-for-aws:v1.0.1 - bucket <bucket-name> - backup-location-config region=<region> - snapshot-location-config region=<region> - secret-file C:\Users\Lenovo\.aws\credentials
  • Linux/MacOS:
velero install - provider aws - plugins velero/velero-plugin-for-aws:v1.0.1 - bucket <bucket-name> - backup-location-config region=<region> - snapshot-location-config region=<region> - secret-file ~/.aws/credentials
NOTE: Step10 and Step11 can be used according to your needs. Step10 is for testing/Verification and Step11 is for migration.

Restore command

velero restore create - from-backup <backup-name>

Conclusion

Velero is a powerful tool that simplifies the process of backing up and restoring Kubernetes cluster resources and persistent volumes in AWS EKS. In this guide, we’ve covered the essential steps to create backups, restore them, and even migrate resources between clusters. Let’s summarize the key takeaways:

  • Creating an AWS EKS Cluster: Before you can use Velero, you need an EKS cluster. We demonstrated how to create and manage one using eksctl.
  • Setting Up Prerequisites: Ensure you have the necessary tools installed, including Homebrew, kubectl, AWS CLI, and eksctl, as they are crucial for working with EKS and Velero.
  • Creating an S3 Bucket: Velero relies on an S3 bucket to store backups. We showed how to create one using the AWS CLI.
  • Installing Velero: Velero can be installed using package managers like Chocolatey or Homebrew. Make sure to specify your AWS S3 bucket and region during installation.
  • Verifying the Installation: Confirm that Velero is installed and running by checking its status using kubectl.
  • Deploying a Test Application: To demonstrate backup and restore, we deployed a sample application to a Kubernetes namespace.
  • Backing Up and Describing Backups: We created a backup of our application and described its details using Velero’s commands.
  • Restoring Backups: We showcased how to restore the backup on the same cluster, effectively recovering our application and its data.
  • Restoring to Another EKS Cluster: For disaster recovery or migration purposes, you can install Velero on another EKS cluster and use the same S3 bucket to restore backups.

Velero provides a seamless solution for protecting your Kubernetes workloads in AWS EKS. It ensures that your applications and data are safe, allowing you to recover from unforeseen events and migrate resources with ease. By following the steps outlined in this guide, you can confidently manage backups and restores in your EKS environment. Remember to adapt the instructions to your specific needs and always follow best practices for security and data management in AWS EKS.

With Velero, you’re equipped to handle the challenges of Kubernetes cluster management in AWS EKS more efficiently, making your operations more resilient and your development workflows smoother.

Happy cluster management!

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *