Velero is an open-source tool for backing up and restoring Kubernetes cluster resources and persistent volumes. It’s essential for disaster recovery and cluster migration.
Prerequisites
Running Kubernetes cluster
AWS account with S3 access
AWS CLI installed and configured
Installing Velero Client
Download Velero
wget https://github.com/vmware-tanzu/velero/releases/download/v1.13.0/velero-v1.13.0-linux-amd64.tar.gz
Extract Archive
tar -xvf velero-v1.13.0-linux-amd64.tar.gz
Install Binary
cp velero-v1.13.0-linux-amd64/velero /usr/local/bin
AWS Configuration
# Download AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Configure credentials
aws configure
Create S3 Bucket
BUCKET =< YOUR_BUCKET >
REGION =< YOUR_REGION >
aws s3api create-bucket \
--bucket $BUCKET \
--region $REGION \
--create-bucket-configuration LocationConstraint= $REGION
Ensure you remove “block public access” settings from the S3 bucket for Velero to function properly.
Setting Up IAM Permissions
Create IAM User
aws iam create-user --user-name velero
Create Policy Document
cat > velero-policy.json << EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeVolumes",
"ec2:DescribeSnapshots",
"ec2:CreateTags",
"ec2:CreateVolume",
"ec2:CreateSnapshot",
"ec2:DeleteSnapshot"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:DeleteObject",
"s3:PutObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts"
],
"Resource": [
"arn:aws:s3:::${ BUCKET }/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::${ BUCKET }"
]
}
]
}
EOF
Attach Policy to User
aws iam put-user-policy \
--user-name velero \
--policy-name velero \
--policy-document file://velero-policy.json
Create Access Key
aws iam create-access-key --user-name velero
Save the access key ID and secret access key from the output.
Create Credentials File
cat > ~/credentials-velero << EOF
[default]
aws_access_key_id=<AWS_ACCESS_KEY_ID>
aws_secret_access_key=<AWS_SECRET_ACCESS_KEY>
EOF
Installing Velero Server
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.9.0 \
--bucket $BUCKET \
--backup-location-config region= $REGION \
--snapshot-location-config region= $REGION \
--secret-file ./credentials-velero
Verify Installation
# Check Velero resources
kubectl -n velero get all
# Check Velero logs
kubectl logs deployment/velero -n velero
Backup Examples
Namespace Backup
Create Test Namespace
kubectl create namespace prod
# Deploy some applications
Backup Namespace
velero backup create prod-backup --include-namespaces prod
Simulate Disaster
kubectl delete ns prod
kubectl get ns
Restore from Backup
velero restore create --from-backup prod-backup
Entire Cluster Backup
velero backup create < backup-nam e >
Label-Based Backup
Backup resources based on labels:
velero backup create < backup-nam e > --selector < ke y > = < valu e >
Scheduled Backups
Create Backup Schedule
Create a daily backup at 5 AM using cron syntax: velero schedule create morning-daily --schedule= "0 5 * * *"
Trigger Manual Backup from Schedule
velero backup create --from-schedule morning-schedule
Scheduled backups use standard cron syntax:
0 5 * * * - Every day at 5:00 AM
0 */6 * * * - Every 6 hours
0 0 * * 0 - Every Sunday at midnight
Managing Backups
List Backups
Describe Backup
velero backup describe < backup-nam e >
velero backup logs < backup-nam e >
Delete Backups
Delete Custom Resource Only
Delete Backup and Data
# Deletes the backup CR but keeps data in S3
kubectl delete backup < backupNam e > -n velero
Use velero backup delete to completely remove backups from both Kubernetes and object storage. Using kubectl delete only removes the Kubernetes resource.
Backup to Different Cluster
Velero supports backing up from one cluster and restoring to another:
Install Velero on both clusters pointing to the same S3 bucket
Take backup on source cluster
Run restore on target cluster
# On target cluster
velero restore create --from-backup prod-backup
Uninstalling Velero
kubectl delete namespace/velero clusterrolebinding/velero
kubectl delete crds -l component=velero
Best Practices
Schedule regular backups for critical namespaces
Test restore procedures regularly
Monitor backup status and set up alerts
Use retention policies to manage storage costs
Keep Velero plugins updated
Document your backup and restore procedures
Velero backups are stored in S3, making them resilient to cluster failures. Always verify backups appear in your S3 bucket after creation.