How to back up Managed Kubernetes using Velero
Velero backs up the resources in a Kubernetes cluster and restores them when you need them. This guide walks you through creating an UpCloud Managed Object Storage service and bucket with Terraform, installing Velero on an UpCloud Managed Kubernetes cluster, and then backing up and restoring a small test app, including its persistent volume.
Velero stores the backed-up Kubernetes resources in the Managed Object Storage bucket. Persistent volumes are backed up as CSI snapshots, which stay in the same storage system as the original volume instead of in the bucket. Because of this, you can restore a volume only in the location where the backup was taken.
Prerequisites
You need:
- A running Managed Kubernetes cluster and its kubeconfig file
- Terraform
- kubectl
- The Velero CLI
- An API token for your UpCloud account
Export the token and the path to your kubeconfig file:
export UPCLOUD_TOKEN=ucat_Your_API_Token
export KUBECONFIG=/path/to/your/kubeconfig.yamlCreating the Terraform configuration
Velero needs an S3-compatible bucket for the backup files. The Terraform configuration below creates a Managed Object Storage service, a bucket called velero, and a user with an access key that Velero signs in with.
Create an empty directory for the configuration and move into it:
mkdir velero-backups && cd velero-backupsCreate provider.tf, which pins the UpCloud provider. The provider reads your API token from the UPCLOUD_TOKEN environment variable.
terraform {
required_providers {
upcloud = {
source = "UpCloudLtd/upcloud"
version = "~> 5.49"
}
}
}
provider "upcloud" {}Create variables.tf with the Managed Object Storage region and the bucket name. Pick the region closest to your cluster. Managed Object Storage availability lists the locations in each region.
variable "region" {
default = "europe-2"
description = "Managed Object Storage region. Pick the region closest to your cluster."
type = string
}
variable "bucket_name" {
default = "velero"
description = "Name of the bucket Velero stores backups in."
type = string
}Create main.tf with the Managed Object Storage service, the bucket and the user:
# Managed Object Storage service for the backups
resource "upcloud_managed_object_storage" "velero" {
name = "velero-backups"
region = var.region
configured_status = "started"
network {
family = "IPv4"
name = "public"
type = "public"
}
}
# Bucket for the backup files
resource "upcloud_managed_object_storage_bucket" "velero" {
service_uuid = upcloud_managed_object_storage.velero.id
name = var.bucket_name
}
# User that Velero signs in as, with full S3 access to the service
resource "upcloud_managed_object_storage_user" "velero" {
service_uuid = upcloud_managed_object_storage.velero.id
username = "velero"
}
resource "upcloud_managed_object_storage_user_policy" "velero" {
service_uuid = upcloud_managed_object_storage.velero.id
username = upcloud_managed_object_storage_user.velero.username
name = "ECSS3FullAccess"
}
resource "upcloud_managed_object_storage_user_access_key" "velero" {
service_uuid = upcloud_managed_object_storage.velero.id
username = upcloud_managed_object_storage_user.velero.username
status = "Active"
}The ECSS3FullAccess policy gives the user full access to every bucket in the service, which suits a service that holds only Velero backups. If you store other data in the same service, attach a policy that's limited to the velero bucket instead.
Create outputs.tf, which gives Velero the endpoint, region, bucket and credentials it needs:
output "s3_url" {
value = "https://${[for e in upcloud_managed_object_storage.velero.endpoint : e.domain_name if e.type == "public"][0]}"
}
output "region" {
value = var.region
}
output "bucket" {
value = upcloud_managed_object_storage_bucket.velero.name
}
output "credentials" {
sensitive = true
value = <<-EOT
[default]
aws_access_key_id=${upcloud_managed_object_storage_user_access_key.velero.access_key_id}
aws_secret_access_key=${upcloud_managed_object_storage_user_access_key.velero.secret_access_key}
EOT
}Creating the Managed Object Storage service
Initialize the directory, which downloads the UpCloud provider:
terraform initPreview the resources Terraform is about to create:
terraform planThen create them:
terraform applyWhen the apply finishes, check the outputs:
terraform outputbucket = "velero"
credentials = <sensitive>
region = "europe-2"
s3_url = "https://a1b2c.upcloudobjects.com"Velero reads the access key from a file. Write the credentials output to a file called credentials-velero, and make it readable only by you:
terraform output -raw credentials > credentials-velero
chmod 600 credentials-veleroInstalling Velero
Install Velero on the cluster with its AWS plugin, which works with any S3-compatible storage. The command takes the bucket, region and endpoint from the Terraform outputs.
velero install \
--provider aws \
--features=EnableCSI \
--plugins velero/velero-plugin-for-aws:v1.15.0 \
--bucket $(terraform output -raw bucket) \
--secret-file ./credentials-velero \
--backup-location-config region=$(terraform output -raw region),s3ForcePathStyle=true,s3Url=$(terraform output -raw s3_url),checksumAlgorithm= \
--use-volume-snapshots=falseA few of the options need explaining:
--features=EnableCSIturns on CSI snapshots, which Velero uses to back up persistent volumes.checksumAlgorithm=(with an empty value) is required. Without it, every backup fails withXAmzContentSHA256Mismatch, because by default the AWS plugin sends a type of upload checksum that Managed Object Storage doesn't support.--use-volume-snapshots=falseturns off Velero's own volume snapshotter. CSI snapshots don't need it.
The command ends by confirming the installation:
Velero is installed! ⛵ Use 'kubectl logs deployment/velero -n velero' to view the status.Velero uses a snapshot class for CSI snapshots only if the class has Velero's label. Add the label to the snapshot class that Managed Kubernetes provides:
kubectl label volumesnapshotclasses.snapshot.storage.k8s.io upcloud-csi-snapshotclass velero.io/csi-volumesnapshot-class="true"Check that Velero can reach the bucket. The phase changes to Available once Velero has validated the backup location.
velero backup-location getNAME PROVIDER BUCKET/PREFIX PHASE LAST VALIDATED ACCESS MODE DEFAULT
default aws velero Available 2026-11-26 22:59:45 +0800 +08 ReadWrite trueDeploying a test app
The test app is an nginx deployment that writes its access log to a persistent volume, so you can see what the backup and the restore bring back. The app also shows how Velero's backup hooks work: annotations on the deployment run a command in the pod before and after each backup.
Create a file called velero-demo-app.yaml with the following content:
---
apiVersion: v1
kind: Namespace
metadata:
name: velero-demo
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nginx-logs
namespace: velero-demo
labels:
app: velero-app
spec:
storageClassName: upcloud-block-storage-maxiops
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: velero-demo
labels:
app: velero-app
spec:
replicas: 1
selector:
matchLabels:
app: velero-app
template:
metadata:
labels:
app: velero-app
annotations:
# Velero supports running scripts before and after a backup is taken,
# as well as before and after a restore is done.
pre.hook.backup.velero.io/command: '["/bin/bash", "-c", "echo prehook > /var/log/nginx/prehook.txt"]'
post.hook.backup.velero.io/command: '["/bin/bash", "-c", "echo posthook > /var/log/nginx/posthook.txt"]'
spec:
volumes:
- name: nginx-logs
persistentVolumeClaim:
claimName: nginx-logs
containers:
- image: nginx:latest
name: nginx
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/var/log/nginx"
name: nginx-logs
readOnly: false
---
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx-lb
name: lb-nginx
namespace: velero-demo
spec:
ports:
- port: 80
targetPort: 80
selector:
app: velero-app
type: LoadBalancerDeploy the app:
kubectl apply -f velero-demo-app.yamlOnce the load balancer is up, load the default nginx welcome page:
curl -i $(kubectl get services -n velero-demo lb-nginx -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')Check that the page loads appear in the nginx log on the persistent volume:
kubectl exec -n velero-demo deployment/nginx -- cat /var/log/nginx/access.logBacking up the app
Persistent volumes on Managed Kubernetes are kept by default when their claim is deleted. To show that the restore really brings the volume back, change the reclaim policy of this one volume to Delete, so that it's removed along with its claim:
kubectl patch pv $(kubectl get pvc nginx-logs -n velero-demo -o jsonpath='{.spec.volumeName}') -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'Note the timestamps in the nginx log, then create the backup. The label selector limits the backup to the test app's resources, but Velero can also back up whole namespaces.
velero backup create velerotest1 --selector app=velero-app --waitBackup request "velerotest1" submitted successfully.
Waiting for backup to complete. You may safely press ctrl-c to stop waiting - your backup will continue in the background.
...........
Backup completed with status: Completed. You may check for more information using the commands `velero backup describe velerotest1` and `velero backup logs velerotest1`.Load the welcome page a few more times. These log entries come after the backup, so they won't be there after the restore.
curl -i $(kubectl get services -n velero-demo lb-nginx -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
kubectl exec -n velero-demo deployment/nginx -- cat /var/log/nginx/access.logThe backup hooks also wrote two files, prehook.txt and posthook.txt, to the log folder:
kubectl exec -n velero-demo deployment/nginx -- ls -la /var/log/nginx/Restoring the app
Delete the deployment and its persistent volume claim. Because of the reclaim policy you changed, the volume is deleted too.
kubectl delete deployments.apps -n velero-demo nginx
kubectl delete pvc -n velero-demo nginx-logsRestore the app from the backup:
velero restore create --from-backup velerotest1 --waitVelero restores the deployment and creates a new volume from the CSI snapshot. When the restore has completed, load the welcome page again:
curl -i $(kubectl get services -n velero-demo lb-nginx -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')Then check the log:
kubectl exec -n velero-demo deployment/nginx -- cat /var/log/nginx/access.logThe log has the entries from before the backup and the page load you just made, but not the entries from between the backup and the restore.
The backup files are in the velero bucket. To browse them, open the velero-backups service under Object Storage in the Control Panel, go to the Buckets tab and select the velero bucket. The bucket holds only the Kubernetes resources, not the CSI snapshots.
Cleaning up
Change the reclaim policy of the restored volume to Delete, so that it's removed with the app:
kubectl patch pv $(kubectl get pvc nginx-logs -n velero-demo -o jsonpath='{.spec.volumeName}') -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'Remove the test app:
kubectl delete -f velero-demo-app.yamlDelete the backup, which also deletes its CSI snapshot:
velero backup delete velerotest1 --confirmRemove Velero from the cluster:
velero uninstallThen remove the Managed Object Storage service, its bucket and its user:
terraform destroy