Backup and Restoration
Velero Overview
Velero is an open-source backup and recovery tool designed specifically for Kubernetes environments. It enables administrators and platform teams to back up, restore, and migrate Kubernetes cluster resources and persistent storage data in a reliable and repeatable way.
In a Kubernetes cluster, critical information such as deployments, services, configuration data, secrets, and persistent volumes are distributed across many components. Velero helps protect this information by capturing the state of the cluster and storing it securely in external object storage, such as AWS S3, Azure Blob Storage, or Google Cloud Storage.
Velero is commonly used for:
Disaster recovery – restoring workloads and data after accidental deletion, misconfiguration, or cluster failure.
Cluster upgrades and maintenance – providing a rollback option before making significant changes.
Environment migration – moving applications and resources between clusters (for example, development to production, or on-premises to cloud).
Environment replication – cloning namespaces or workloads for testing and troubleshooting.
Important
Velero is used to protect our Kubernetes environments and reduce the risks associated with system failures, human error, and infrastructure changes. Kubernetes clusters are highly dynamic, and without a reliable backup and restore solution, recovering from incidents can be time-consuming and complex.
Velero Installation
For more information on installing Velero, please see https://velero.io/docs/v1.15/basic-install/
Note
This is applicable for Cloud deployments only as Velero CLI is already provided with On-premises deployments.
Configure Azure Plugin
Prerequisites
Local Administrator Rights
Config file of the desired cluster (e.g KA-Azure.config)
The following steps show how to configure Azure plugin for Velero by enabling backups in a specific resource group (in which Velero will have access to its storage account and blob container to store backups).
Note
If you want to use AAD Pod Identity or use storage account access key instead of creating a service principal, please follow this guide https://github.com/vmware-tanzu/velero-plugin-for-microsoft-azure
Create the Storage Account and Blob Container. Please replace the below variables with your environment values.
Location: XXX
Azure Subscription Name: YYY
Azure Resource Group: MC_XX-AKS_yy
AZURE_BACKUP_RESOURCE_GROUP=Velero_Backups az group create -n $AZURE_BACKUP_RESOURCE_GROUP --location XXX --subscription "YYY" AZURE_STORAGE_ACCOUNT_ID="velero$(uuidgen | cut -d '-' -f5 | tr '[A-Z]' '[a-z]')" az storage account create \ --name $AZURE_STORAGE_ACCOUNT_ID \ --resource-group $AZURE_BACKUP_RESOURCE_GROUP \ --subscription "XXX" \ --sku Standard_GRS \ --encryption-services blob \ --https-only true \ --min-tls-version TLS1_2 \ --kind BlobStorage \ --access-tier Hot BLOB_CONTAINER=velero az storage container create -n $BLOB_CONTAINER --public-access off --account-name $AZURE_STORAGE_ACCOUNT_ID --subscription "YYY"
Identify the AKS Managed Resource Group. Please replace the below variables with your environment values.
Azure Resource Group
Note
AZURE_RESOURCE_GROUP must be set to the name of the Azure-managed resource group that is automatically created when the AKS cluster is provisioned. This resource group contains the cluster's virtual machines and managed disks.
az group list --query '[].{ ResourceGroup: name, Location:location }' --subscription "YYY" AZURE_RESOURCE_GROUP="MC_XX-AKS_yy"Retrieve the Azure Subscription ID and Azure Tenant ID. These values are added to the Velero credentials file so Velero can authenticate with Azure and access resources in the correct subscription.
AZURE_SUBSCRIPTION_ID=`az account list --query '[?isDefault].id' -o tsv` AZURE_TENANT_ID=`az account list --query '[?isDefault].tenantId' -o tsv`
Create the Service Principal. Please replace the below variables with your environment values.
Azure Subsciption ID: xxxxx-yyyyy
AZURE_CLIENT_SECRET=`az ad sp create-for-rbac --name "velero" --role "Contributor" --query 'password' --scopes /subscriptions/xxxxx-yyyyy -o tsv` AZURE_CLIENT_ID=`az ad sp list --display-name "velero" --query '[0].appId' -o tsv`
Create Velero Credentials File. Please replace the below variables with your environment values.
cat << EOF > ./credentials-velero AZURE_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID} AZURE_TENANT_ID=${AZURE_TENANT_ID} AZURE_CLIENT_ID=${AZURE_CLIENT_ID} AZURE_CLIENT_SECRET=${AZURE_CLIENT_SECRET} AZURE_RESOURCE_GROUP=${AZURE_RESOURCE_GROUP} AZURE_CLOUD_NAME=AzurePublicCloud EOF
Define the Velero and Plugins version. Please replace the below variables with your environment values.
Private Reg (your container registry)
PRIVATE_REG=<your private registry> VELERO_VERSION=<version of Velero you're targeting, for example v1.12.0> PLUGIN_VERSION=<version of plugin you're targeting, for example v1.6.0>Install Velero
velero install \ --provider azure \ --image $PRIVATE_REG/velero/velero:$VELERO_VERSION \ --plugins $PRIVATE_REG/velero/velero-plugin-for-microsoft-azure:$PLUGIN_VERSION \ --bucket $BLOB_CONTAINER \ --secret-file ./credentials-velero \ --backup-location-config resourceGroup=$AZURE_BACKUP_RESOURCE_GROUP,storageAccount=$AZURE_STORAGE_ACCOUNT_ID \ --snapshot-location-config apiTimeout=5m,resourceGroup=$AZURE_BACKUP_RESOURCE_GROUP,subscriptionId=$AZURE_BACKUP_SUBSCRIPTION_ID \ --kubeconfig KA-Azure.configAdd a Node Selector and secret to the Velero Deployment.
kubectl patch deploy velero --namespace kappa-backup --kubeconfig KA-Azure.config --type merge --patch '{ "spec": { "template": { "spec": { "nodeSelector": { "kubernetes.io/os": "linux"} } } } }'kubectl patch deployment velero -n velero --type='json' -p='[{"op": "add", "path": "/spec/template/spec/imagePullSecrets", "value":[{"name": "thirdparties-acr-secret"}]}]' \ --kubeconfig /mnt/fra-prototypes/.kube/aks-testing.configNote
For more information please see https://github.com/vmware-tanzu/velero-plugin-for-microsoft-azure
Configure AWS Plugin
Prerequisites
Local Administrator Rights
Config file of the desired cluster (e.g KA-Azure.config)
The following steps show how to configure the AWS plugin for Velero by enabling backups to an Amazon S3 bucket, which Velero will use to store backup data and volume snapshots for the target Kubernetes cluster.
Install Velero CLI.
curl -LO https://github.com/vmware-tanzu/velero/releases/download/v1.18.2/velero-v1.18.2-linux-amd64.tar.gz tar -zxvf velero-v1.18.2-linux-amd64.tar.gz sudo mv velero-v1.18.2-linux-amd64/velero /usr/local/bin/velero velero version --client-only
Create the S3 Bucket. Please replace the below variables with your environment values.
Bucket: kappa-velero-backup
Region: eu-west-1
BUCKET=kappa-velero-backup REGION=eu-west-1 aws s3api create-bucket \ --bucket $BUCKET \ --region $REGION \ --create-bucket-configuration LocationConstraint=$REGIONCreate IAM User (if not already created).
aws iam create-user --user-name velero
Create IAM policy file (velero-policy.json).
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:PutObjectTagging", "s3:AbortMultipartUpload", "s3:ListMultipartUploadParts" ], "Resource": [ "arn:aws:s3:::${BUCKET}/*" ] }, { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::${BUCKET}" ] } ] } EOFAttach the IAM policy to the IAM user.
aws iam put-user-policy \ --user-name velero \ --policy-name velero \ --policy-document file://velero-policy.jsonCreate IAM access keys.
aws iam create-access-key --user-name velero
The result should look similar to the below;
{ "AccessKey": { "UserName": "velero", "Status": "Active", "CreateDate": "2017-07-31T22:24:41.576Z", "SecretAccessKey": <AWS_SECRET_ACCESS_KEY>, "AccessKeyId": <AWS_ACCESS_KEY_ID> } }Create Velero Credentials File (credentials-velero). Please use the IAM access keys which were generated in Step 6.
[default] aws_access_key_id=<AWS_ACCESS_KEY_ID> aws_secret_access_key=<AWS_SECRET_ACCESS_KEY>
Install Velero
velero install \ --provider aws \ --plugins velero/velero-plugin-for-aws:v1.14.2 \ --bucket $BUCKET \ --backup-location-config region=$REGION \ --snapshot-location-config region=$REGION \ --secret-file ./credentials-veleroVerify Installation
kubectl get pods -n velero kubectl get backupstoragelocation -n velero
You should now see the velero pod running and the backup location available.
Configure AWS Plugin using IRSA
The following steps show how to deploy Velero on an Amazon EKS cluster using IAM Roles for Service Accounts (IRSA), allowing Velero to securely access AWS resources without requiring IAM user access keys.
Create the Velero IAM Policy
Note
The below example assumes that the 'kappa-velero-backup' S3 storage is being used.
vi velero-irsa-policy.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ec2:CreateVolume", "ec2:CreateTags", "ec2:DescribeVolumes", "ec2:DescribeVolumeAttribute", "ec2:DescribeVolumeStatus", "ec2:DescribeSnapshots", "ec2:DescribeAvailabilityZones", "ec2:CreateSnapshot", "ec2:DeleteSnapshot" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:AbortMultipartUpload", "s3:ListMultipartUploadParts" ], "Resource": [ "arn:aws:s3:::kappa-velero-backup/*" ] }, { "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::kappa-velero-backup" ] } ] }velero-irsa-policy.json defines EC2 (snapshot) and S3 (backup) permissions.
aws iam create-policy --policy-name velero-irsa-policy --policy-document file://velero-irsa-policy.json
Create the IRSA IAM Role
- Retrieve account ID. Replace <ACCOUNT_ID> with yours.
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
vi velero-irsa-trust.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::416884031218:oidc-provider/oidc.eks.eu-west-1.amazonaws.com/id/<ACCOUNT_ID>" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "oidc.eks.eu-west-1.amazonaws.com/id/<ACCOUNT_ID>:sub": "system:serviceaccount:velero-irsa:velero-irsa-server" } } } ] }Create IAM role.
aws iam create-role --role-name velero-irsa-role --assume-role-policy-document file://velero-irsa-trust.json
Attach the IAM policy to the IAM user.
aws iam attach-role-policy --role-name velero-irsa-role --policy-arn arn:aws:iam::<ACCOUNT_ID>:policy/velero-irsa-policy
Associate the EKS Cluster with an IAM OIDC Provider. This is required to enable token-based authentication for IRSA.
curl --silent --location "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv /tmp/eksctl /usr/local/bin eksctl utils associate-iam-oidc-provider --cluster ka --region eu-west-1 --approve
Deploy Velero Using IRSA (Helm). Velero runs in the namespace 'velero'.
helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts helm repo update helm install velero vmware-tanzu/velero --namespace velero --create-namespace --set configuration.backupStorageLocation[0].name=irsa-backup-bsl --set configuration.backupStorageLocation[0].provider=aws --set configuration.backupStorageLocation[0].bucket=kappa-velero-backup --set configuration.backupStorageLocation[0].prefix=irsa-backup --set configuration.backupStorageLocation[0].config.region=eu-west-1 --set configuration.volumeSnapshotLocation[0].name=default --set configuration.volumeSnapshotLocation[0].provider=aws --set configuration.volumeSnapshotLocation[0].config.region=eu-west-1 --set snapshotsEnabled=true --set credentials.useSecret=false --set serviceAccount.server.create=true --set serviceAccount.server.annotations."eks.amazonaws.com/role-arn"="arn:aws:iam::<ACCOUNT_ID>:role/velero-irsa-role" --set initContainers[0].name=velero-plugin-for-aws --set initContainers[0].image=velero/velero-plugin-for-aws:v1.7.1 --set initContainers[0].volumeMounts[0].mountPath=/target --set initContainers[0].volumeMounts[0].name=plugins
Or using our Azure registry after having created ka-acr-secret in velero-irsa namespace with the right credentials
helm install velero-irsa vmware-tanzu/velero \ --namespace velero-irsa \ --create-namespace \ --set configuration.backupStorageLocation[0].name=irsa-test-bsl \ --set configuration.backupStorageLocation[0].provider=aws \ --set configuration.backupStorageLocation[0].bucket=kappa-velero-backup \ --set configuration.backupStorageLocation[0].prefix=irsa-test \ --set configuration.backupStorageLocation[0].config.region=eu-west-1 \ --set configuration.volumeSnapshotLocation[0].name=default \ --set configuration.volumeSnapshotLocation[0].provider=aws \ --set configuration.volumeSnapshotLocation[0].config.region=eu-west-1 \ --set snapshotsEnabled=true \ --set credentials.useSecret=false \ --set serviceAccount.server.create=true \ --set serviceAccount.server.annotations."eks\.amazonaws\.com/role-arn"="arn:aws:iam::<ACCOUNT_ID>:role/velero-irsa-role" \ --set image.repository='your registry' \ --set image.tag=v1.18.2 \ --set image.pullPolicy=IfNotPresent \ --set kubectl.image.repository='your registry' \ --set kubectl.image.tag=1.33.1 \ --set initContainers[0].name=velero-plugin-for-aws \ --set initContainers[0].image= \ --set initContainers[0].imagePullPolicy=IfNotPresent \ --set initContainers[0].volumeMounts[0].mountPath=/target \ --set initContainers[0].volumeMounts[0].name=plugins \ --set image.imagePullSecrets[0]='your registry secret'Another way to install it is to create a values.yaml file containing the below;
configuration: backupStorageLocation: - name: irsa-test-bsl provider: aws bucket: prefix: irsa-test config: region: eu-west-1 volumeSnapshotLocation: - name: default provider: aws config: region: eu-west-1 snapshotsEnabled: true credentials: useSecret: false serviceAccount: server: create: true annotations: eks.amazonaws.com/role-arn: "arn:aws:iam::416884031218:role/velero-irsa-role" image: repository: 'your registry' tag: v1.18. pullPolicy: IfNotPresent imagePullSecrets: - 'your registry secret' kubectl: image: repository: 'your registry'/velero/velero-plugin-for-aws:v1.14.2 tag: 1.33.1 initContainers: - name: velero-plugin-for-aws image: imagePullPolicy: IfNotPresent volumeMounts: - mountPath: /target name: pluginsAnd install Velero using this command.
helm install velero vmware-tanzu/velero \ --namespace velero-irsa \ --create-namespace \ -f values.yamlValidate Backup Storage Location.
kubectl get backupstoragelocation -n velero
The result should look similar to the below;
NAME PHASE LAST VALIDATED irsa-backup-bsl Available
Run a Backup.
velero backup create kappa --include-namespaces kappa,kappa-monitoring,kappa-postgres,kappa-redis,keda,garage --ttl 72h0m0s -n velero --storage-location irsa-test-bsl
Run a Restore.
velero restore create kappa --from-backup kappa -n velero
Velero Backup and Restore
The following section show how to create manual and scheduled backups using Velero, monitor backup progress, and restore Kubernetes resources from an existing backup when required.
Note
The way in which Velero commands are executed depends on the deployment type.
For Cloud deployments, you will need to run Velero commands directly from a host where the Velero CLI is installed, using the appropriate kubeconfig and namespace configuration. The namespace will be dependant on how you have configured it within your cluster, by default the namespace is 'velero'.
export KUBECONFIG=/mnt/fra-prototypes/.kube/'yourkubeconfig'.config kubectl config set-context --current --namespace=velero velero get backup
For On-Premises deployments, a dedicated 'velero-cli' pod is deployed in the 'kappa-backup' namespace.
You can either execute commands from any host using;
kubectl exec -n kappa-backup deploy/velero-cli -- velero get backup
Or open a terminal in the 'velero-cli' pod (for example, using Lens) and run Velero commands directly without specifying the kubeconfig file and namespace;
velero get backup
Manual Backups
Test a manual backup (in this example; RabbitMQ).
velero backup create rabbitmq --include-namespaces kappa --selector app=rabbitmq --ttl 2h0m0s
Start a manual backup of the two namespaces.
velero backup create kappa --include-namespaces kappa,kappa-monitoring,kappa-postgres,kappa-redis,keda,garage --ttl 72h0m0s --csi-snapshot-timeout 4h0m0s
Monitor the backup of these namespaces.
- View detailed information on the backup
velero backup describe kappa --details
- View backup logs
velero backup logs kappa
Note
Note: When using Velero with Longhorn and the Data Mover, only the used capacity of each Persistent Volume Claim (PVC) is backed up, rather than the entire provisioned volume size. In addition, any Longhorn snapshots created by Velero are temporary and are automatically deleted once the backup completes successfully. These snapshots remain visible only if the backup process fails.
Scheduled Backups
This example shows how to create a backup every night at 1am and delete any backups older than 3 days.
velero schedule create kappa-schedule --schedule="0 1 * * *" --include-namespaces kappa,kappa-monitoring,kappa-postgres,kappa-redis,keda,garage --ttl 72h0m0s --csi-snapshot-timeout 4h0m0s
Restore
Warning
Velero only restores resources that do not already exist in the cluster. Therefore, before restoring a resource, it must first be removed from the target cluster.
List all available backups (for example kappa-schedule-XXX).
velero get backup
As an example only, to restore the Cassandra StatefulSet in the 'kappa' namespace, the existing StatefulSet must be deleted before running the restore.
kubectl delete sts cassandra
Restore the missing resources.
velero restore create kappa --include-namespaces kappa,kappa-monitoring,kappa-postgres,kappa-redis,keda,garage --from-backup kappa-schedule-XXX
Monitor the restoration with below commands respectively.
velero restore describe kappa velero restore logs kappa
Velero Upgrade
Prerequisites
Local Administrator Rights
Config file of the desired cluster (e.g KA-Azure.config)
The following steps show how to upgrade an existing Velero deployment, update the Velero Custom Resource Definitions (CRDs), upgrade the Velero and plugin container images, and verify that the upgrade has completed successfully.
Verify the Current Velero Version.
velero version --client-only --kubeconfig /mnt/test/.kube/kubeconfig.config
Update the Velero CRDs.
velero install --crds-only --dry-run -o yaml | kubectl apply --kubeconfig /mnt/test/.kube/kubeconfig.config -n velero -f -
Upgrade the Velero and Azure Plugin Images.
kubectl set image deployment/velero \ velero=kacregistry.azurecr.io/velero/velero:v1.15.2 \ velero-velero-plugin-for-microsoft-azure=kacregistry.azurecr.io/velero/velero-plugin-for-microsoft-azure:v1.11.1 \ --namespace velero \ --kubeconfig /mnt/test/.kube/kubeconfig.configConfigure the Image Pull Secret.
kubectl patch deployment velero -n velero --type='json' -p='[{"op": "add", "path": "/spec/template/spec/imagePullSecrets", "value":[{"name": "thirdparties-acr-secret"}]}]' \ --kubeconfig /mnt/test/.kube/kubeconfig.configVerify the Velero Version After the Upgrade.
velero version --kubeconfig /mnt/test/.kube/kubeconfig.config
Copy the Registry Secret to the Target Namespace.
- Export the existing registry secret.
kubectl get secret thirdparties-acr-secret -n kappa --kubeconfig /mnt/test/.kube/kubeconfig.config -o yaml > thirdparties-acr-secret.yaml
- Apply secret to the required namespace.
kubectl apply -f thirdparties-acr-secret.yaml --kubeconfig /mnt/test/.kube/kubeconfig.config
Upgrade the Node Agent DaemonSet (Optional).
kubectl set image daemonset/node-agent \ node-agent=velero/velero:v1.15.0 \ --namespace velero