Skip to content

Instantly share code, notes, and snippets.

@zioproto
Last active November 27, 2023 13:10
Show Gist options
  • Save zioproto/7f76e3fe66ed7de9708f9b5a5e1ea49d to your computer and use it in GitHub Desktop.
Save zioproto/7f76e3fe66ed7de9708f9b5a5e1ea49d to your computer and use it in GitHub Desktop.
Velero

Create a cluster

Option 1 Start minikube

minikube config set cpus 4
minikube config set memory 5000
minikube start

Option 2 Create AKS cluster

az group create \
  --name storage-resource-group \
  --location eastus
az aks create \
 --location eastus \
 --name velero \
 --resource-group storage-resource-group \
 --network-plugin azure  \
 --node-vm-size Standard_DS3_v2 \
 --node-count 2 \
 --auto-upgrade-channel rapid \
 --node-os-upgrade-channel  NodeImage
 
 az aks get-credentials --resource-group storage-resource-group --name velero --overwrite-existing

Create Azure Storage Account and container

Create a storage account

az group create \
  --name storage-resource-group \
  --location eastus

az storage account create --name velerogist \
                          --resource-group storage-resource-group \
                          --location eastus --sku Standard_RAGRS \
                          --kind StorageV2 \
                          --allow-blob-public-access false

Create a storage container

az storage container create \
    --name velerobackups \
    --account-name velerogist 

Get the access key:

AZURE_STORAGE_ACCOUNT_ACCESS_KEY=`az storage account keys list --account-name velerogist --query "[?keyName == 'key1'].value" -o tsv`

Install Velero

Create file with config:

cat << EOF  > ./credentials-velero
AZURE_STORAGE_ACCOUNT_ACCESS_KEY=${AZURE_STORAGE_ACCOUNT_ACCESS_KEY}
AZURE_CLOUD_NAME=AzurePublicCloud
EOF

Install velero

velero install \
  --provider azure \
  --use-node-agent \
  --plugins velero/velero-plugin-for-microsoft-azure:v1.8.0 \
  --bucket velerobackups \
  --secret-file ./credentials-velero \
  --use-volume-snapshots=false \
  --backup-location-config storageAccount=velerogist,storageAccountKeyEnvVar=AZURE_STORAGE_ACCOUNT_ACCESS_KEY

Check storage locations:

kubectl get -n velero BackupStorageLocation

Apply sample application

kubectl apply -f https://raw.githubusercontent.com/vmware-tanzu/velero/main/examples/nginx-app/with-pv.yaml

Note: the fsfreeze hook in the sidecar container of the sample application makes minikube crash. You want to remove the annotations and the sidecar container if testing with minikube.

Generate some logs (works only on AKS)

curl -v $(k get svc -n nginx-example my-nginx -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')

Make a backup

velero backup create aks-backup-2345 --include-namespaces nginx-example --default-volumes-to-fs-backup

Test a restore

az aks create \
 --location eastus \
 --name restore \
 --resource-group storage-resource-group \
 --network-plugin azure  \
 --node-vm-size Standard_DS3_v2 \
 --node-count 2 \
 --auto-upgrade-channel rapid \
 --node-os-upgrade-channel  NodeImage
 
 az aks get-credentials --resource-group storage-resource-group --name restore --overwrite-existing
 
 velero restore create --from-backup  aks-backup-2345
 
 
@zioproto
Copy link
Author

this spec works:

spec:
  config:
    resourceGroup: ""
    storageAccount: velerosaverio
    storageAccountKeyEnvVar: AZURE_STORAGE_ACCOUNT_ACCESS_KEY
  default: true
  objectStorage:
    bucket: velerobackups
  provider: azure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment