Simplify Cluster Backups with Velero
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 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.
How Velero Works?
Each Velero operation – on-demand backup, scheduled backup, restore – is a custom resource, defined with a Kubernetes Custom Resource Definition (CRD) and stored in etcd. Velero also includes controllers that process the custom resources to perform backups, restores, and all related operations.
You can back up or restore all objects in your cluster, or you can filter objects by type, namespace, and/or label.
Velero is ideal for the disaster recovery use case, as well as for snapshotting your application state, prior to performing system operations on your cluster, like upgrades.
Demo - Prerequisites
-
Kubernetes Cluster
-
AWS IAM User Account
Demo
-
Go to Velero CLI Installation page to install
velero. -
Go to
AWS Management Consoleand sign in asIAM-User. -
Navigate to
S3. From the menu on the left, chooseGeneral purpose buckets. -
Choose
Create Bucketand follow these settings:
<YOUR_NAME> with your name to make the bucket name unique.
-
Then, choose
Create bucket. -
Choose the bucket you created. Then, choose
Create folder.
-
Choose
Create folder. Then, go to main page of the bucket again. -
Choose
Create folderagain.
- Choose
Create folder. You should see the following structure:

-
Now, go to
IAM. From the menu on the left, chooseUsers. -
Choose your user and navigate to its page.
-
Under
Permissionssection, chooseAdd permissions -> Create inline policy. -
Choose
JSONasPolicy editorand enter the following:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::velero-backup-mehmet",
"arn:aws:s3:::velero-backup-mehmet/*"
]
},
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "*"
}
]
}
-
Change
<YOUR_BUCKET_NAME>with your bucket name. -
Choose
Next...
-
Choose
Create policy. -
Go to your main page of your IAM user account again.
-
Under
Security credentialssection, chooseCreate access key.
- Choose
Next...
-
Choose
Create access keyand chooseDownload .csv file. -
There is a
credentials.txtfile with the following content:
-
Enter the keys from the
.csvfile. -
Now, open the terminal. Check the status of cluster.
- Configure the
veleroin cluster.
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.0.0 \
--bucket <BUCKET_NAME> \
--backup-location-config region=<REGION> \
--secret-file <PATH_TO_AWS_CREDENTIALS_FILE> \
--pod-annotations iam.amazonaws.com/role=arn:aws:iam::<AWS_ACCOUNT_ID>:user/<AWS_IAM_USER> \
--use-volume-snapshots=false
- Replace the related parts with your information. For example:
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.0.0 \
--bucket velero-backup-mehmet-deneme \
--backup-location-config region=us-east-1 \
--secret-file ./credentials.txt \
--pod-annotations iam.amazonaws.com/role=arn:aws:iam::123456789123:user/mehmet \
--use-volume-snapshots=false
- Run the following command to see the backup location.
- The expected output will be:

- After verifying that backup location is ready, take the backup.
- Open your bucket and check the backup.

- Run the following command to see the backup status.

- Now, create a namespace.
- Deploy a
nginxpod in this namespace.
- Check the status of the pod.
- Take the backup of this cluster.
-
Check the bucket and notice the backup.
-
Now, delete the pod.
- Then, delete the namespace.
- Check the status of the pod.
- Now, restore the namespace and the pod.
- Check the bucket for restoration files.

- Check the status of the pod.
- Also, you can create scheduled backups for every minute.
- Check the backup history.

- Delete the scheduled backups.
- Delete the backups.
- Don't forget to destroy the resources you created.