💾
Container Platform

Velero

Backup and restore Kubernetes clusters and persistent volumes

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

Velero backs up Kubernetes resources and volumes to S3 (or other storage) for disaster recovery.

📥

Step 01

Install Velero

(01)Install Velero

Linux
1# Install Velero CLI
2wget https://github.com/vmware-tanzu/velero/releases/download/v1.14.0/velero-v1.14.0-linux-amd64.tar.gz
3tar xf velero-v1.14.0-linux-amd64.tar.gz
4sudo mv velero-v1.14.0-linux-amd64/velero /usr/local/bin/
⚙️

Step 02

Configure Velero

(01)Configure Velero

Linux
1# Install Velero in cluster (Minikube example — use your bucket provider)
2velero install \
3 --provider aws \
4 --plugins velero/velero-plugin-for-aws:v1.10.0 \
5 --bucket my-backup-bucket \
6 --secret-file ./credentials-velero \
7 --use-volume-snapshots=false
8
9velero backup create first-backup --include-namespaces default

Step 03

Verify

(01)Verify installation

Linux
1velero backup get
2velero schedule get

Step 04

Manage Velero

(01)Common tasks

Linux
1velero restore create --from-backup first-backup
2velero backup delete first-backup

📋Config templates

2 YAML templates for Velero. Copy and deploy after setup.

2 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

pvc.yml

yaml
1apiVersion: v1
2kind: PersistentVolumeClaim
3metadata:
4 name: data-pvc
5spec:
6 accessModes:
7 - ReadWriteOnce
8 resources:
9 requests:
10 storage: 1Gi
11 storageClassName: standard

statefulset.yml

StatefulSet mounting the PVC at /data

yaml
1apiVersion: apps/v1
2kind: StatefulSet
3metadata:
4 name: app-with-storage
5spec:
6 serviceName: app-svc
7 replicas: 1
8 selector:
9 matchLabels:
10 app: app-with-storage
11 template:
12 metadata:
13 labels:
14 app: app-with-storage
15 spec:
16 containers:
17 - name: app
18 image: nginx:alpine
19 ports:
20 - containerPort: 80
21 volumeMounts:
22 - name: data
23 mountPath: /data
24 volumes:
25 - name: data
26 persistentVolumeClaim:
27 claimName: data-pvc
📄

Step 01

Apply PVC + StatefulSet

(01)Create PVC then StatefulSet

Linux
1kubectl apply -f pvc.yml
2kubectl get pvc
3kubectl apply -f statefulset.yml
4kubectl get pods,pvc
5kubectl exec app-with-storage-0 -- ls /data