VOOZH about

URL: https://dzone.com/articles/setup-velero-on-aks

⇱ Setup and Configure Velero on AKS


Related

  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Setup and Configure Velero on AKS

Setup and Configure Velero on AKS

This article will help you to setup Velero easily on AKS, limiting access to the minimum needed resource group instead of subscription level access.

By Mar. 19, 21 · Tutorial
Likes
Comment
Save
16.0K Views

Join the DZone community and get the full member experience.

Join For Free

What Is Velero?

Velero is an open source tool to safely back up and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes

Velero consists of:

  • A server that runs on your cluster.
  • A command-line client that runs locally.

Azure Kubernetes Service (AKS)

Azure Kubernetes Service (AKS) is a managed container orchestration service, based on the Kubernetes system and available on the Microsoft Azure public cloud. AKS is used to deploy, scale and manage both Docker containers and container-based applications across a cluster of container hosts.

Prerequisite

Create resource group and AKS cluster under Azure portal, you can choose the name you like. I created with following details

Create Resource Group

Shell




xxxxxxxxxx
1


1
$ az group create --name myResourceGroup --location eastus



Create Kubernetes Cluster

Shell




xxxxxxxxxx
1


1
$ az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys



Get the Cluster Credentials:

Shell




xxxxxxxxxx
1


1
$ az aks get-credentials --resource-group myResourceGroup --name myAKSCluster



Dynamic Resource Group

Azure created the MC_myresourcegroup_myakscluster_eastus resource group to hold dynamic resources created for my Kubernetes cluster. For example, agent pools, dynamic disks for persistent volumes.  

Once it is done next step is to setup a storage account.

Setup Storage Account 

Shell




xxxxxxxxxx
1


1
$ az storage account create --name mystoragevelero --resource-group myResourceGroup --sku Standard_GRS --encryption-services blob --https-only true --kind BlobStorage --access-tier Hot



Create blob container inside the storage account:

Shell




x



1
$ az storage container create -n velero --public-access off --account-name mystoragevelero



Get your subscription and tenant ID:

Shell




xxxxxxxxxx
1


1
$ az account list --query '[?isDefault].id' -o tsv
2
XXXX-XXXX-XXX-XXX-XXXX-XXXXXXXX
3

 
4
$ az account list --query '[?isDefault].tenantId' -o tsv
5
XXXX-XXXX-XXX-XXX-XXXX-XXXXXXXX



Create a service principal with contributor access:

Shell




xxxxxxxxxx
1


1
$ export SUBSCRIPTION_ID=XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX
2
$ export STORAGE_RESOURCE_GROUP=myResourceGroup
3
$ export MC_RESOURCE_GROUP=MC_myresourcegroup_myakscluster_eastus
4
$ az ad sp create-for-rbac \
5
  --name "velero" \
6
  --role "Contributor" \
7
  --query 'password' \
8
  -o tsv \
9
  --scopes /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$STORAGE_RESOURCE_GROUP /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$MC_RESOURCE_GROUP


Save the password that you got while creating the service principal.

Get the app ID for the service principal:

Shell




xxxxxxxxxx
1


1
$ az ad sp list --display-name "velero" --query '[0].appId' -o tsv


Create a credentials file credentials-velero for Velero, make sure to update the values of subscription id, tenant id, a client id (SP app id), client secret (SP password), and resource group name.

Shell




xxxxxxxxxx
1


1
$ cat credentails-velero
2
AZURE_SUBSCRIPTION_ID=XXXX-XXXX-XXX-XXX-XXXX-XXXXXXXX
3
AZURE_TENANT_ID=XXXX-XXXX-XXX-XXX-XXXX-XXXXXXXX
4
AZURE_CLIENT_ID=SERVICE_PRINCIPAL_APPID
5
AZURE_CLIENT_SECRET=SERVICE_PRINCIPAL_PASSWORD
6
AZURE_RESOURCE_GROUP=MC_myresourcegroup_myakscluster_eastus
7
AZURE_CLOUD_NAME=AzurePublicCloud



Download the Velero client, you can download it from the below URL and setup in your PATH variable:

https://github.com/vmware-tanzu/velero/releases/tag/v1.5.1

Download the Helm client, you can download it from the below URL and setup in your PATH variable:

https://github.com/helm/helm/releases

Once you are done with the above steps, the next step is to install Velero on Kubernetes using helm charts.

Install Velero

Shell




xxxxxxxxxx
1
45


1
$ helm repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts
2

 
3
# Make sure you are setting the values correctly 
4
# --set-file credentials.secretContents.cloud=./credentials-velero 
5
# this file has SP details for velero
6
# --set configuration.backupStorageLocation.config.resourceGroup=myResourceGroup \
7
# --set configuration.backupStorageLocation.config.storageAccount=mystoragevelero \ 
8
# the above 2 configurations will save kubernetes objects tar in storage account.
9
$ helm install --name velero vmware-tanzu/velero --namespace velero \
10
--set-file credentials.secretContents.cloud=./credentials-velero \
11
--set configuration.provider=azure \
12
--set configuration.backupStorageLocation.name=azure \
13
--set configuration.backupStorageLocation.bucket='velero' \
14
--set configuration.backupStorageLocation.config.resourceGroup=myResourceGroup \
15
--set configuration.backupStorageLocation.config.storageAccount=mystoragevelero \
16
--set snapshotsEnabled=true \
17
--set deployRestic=true \
18
--set configuration.volumeSnapshotLocation.name=azure \
19
--set image.repository=velero/velero \
20
--set image.pullPolicy=Always \
21
--set initContainers[0].name=velero-plugin-for-microsoft-azure \
22
--set initContainers[0].image=velero/velero-plugin-for-microsoft-azure:master \
23
--set initContainers[0].volumeMounts[0].mountPath=/target \
24
--set initContainers[0].volumeMounts[0].name=plugins
25

 
26
NAME: velero
27
LAST DEPLOYED: Thu Nov 28 18:10:04 2020
28
NAMESPACE: velero
29
STATUS: deployed
30
REVISION: 1
31
TEST SUITE: None
32
NOTES:
33
Check that the velero is up and running:
34

 
35
   kubectl get deployment/velero -n velero
36

 
37
Check that the secret has been created:
38

 
39
   kubectl get secret/velero -n velero
40

 
41
Once velero server is up and running you need the client before you can use it
42
1. wget https://github.com/vmware-tanzu/velero/releases/download/v1.5.2/velero-v1.5.2-darwin-amd64.tar.gz
43
2. tar -xvf velero-v1.5.2-darwin-amd64.tar.gz -C velero-client
44

 
45
More info on the official site: https://velero.io/docs
46

 
47
$ kubectl get pods -n velero
48
NAME                     READY   STATUS   RESTARTS   AGE
49
restic-86ty8              1/1     Running   0         1d
50
restic-kdr5t              1/1     Running   0         1d
51
restic-pjbhn              1/1     Running   0         1d
52
velero-742b785c76-j8bcf   1/1     Running   0         1d
53

 



Once you are done with the configuration, now it is time to take up the backup and snapshots.

Velero by default takes the snapshots of all the persistent volumes mounted in a particular namespace. 

Backup and Snapshot

Check the backup location:

Shell




x


1
$ velero backup-location get
2
NAME PROVIDER BUCKET/PREFIX PHASE LAST VALIDATED ACCESS MODE
3
azure azure velero Available 2021-03-19 20:09:54 +0530 IST ReadWrite



Install WordPress:

Shell




x


1
$ kubectl create ns wp
2
namespace/wp created
3

 
4
$ helm install my-app bitnami/wordpress --namespace wp
5
NAME: my-app
6
LAST DEPLOYED: Fri Mar 19 19:53:36 2021
7
NAMESPACE: wp
8
STATUS: deployed
9
REVISION: 1
10
NOTES:
11
** Please be patient while the chart is being deployed **
12

 
13
Your WordPress site can be accessed through the following DNS name from within your cluster:
14

 
15
 my-app-wordpress.wp.svc.cluster.local (port 80)
16

 
17
To access your WordPress site from outside the cluster follow the steps below:
18

 
19
1. Get the WordPress URL by running these commands:
20

 
21
 NOTE: It may take a few minutes for the LoadBalancer IP to be available.
22
 Watch the status with: 'kubectl get svc --namespace wp -w my-app-wordpress'
23

 
24
 export SERVICE_IP=$(kubectl get svc --namespace wp my-app-wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
25
 echo "WordPress URL: http://$SERVICE_IP/"
26
 echo "WordPress Admin URL: http://$SERVICE_IP/admin"
27

 
28
2. Open a browser and access WordPress using the obtained URL.
29

 
30
3. Login with the following credentials below to see your blog:
31

 
32
 echo Username: user
33
 echo Password: $(kubectl get secret --namespace wp my-app-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)
34

 
35
$ kubectl get svc --namespace wp -w my-app-wordpress
36
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
37
my-app-wordpress LoadBalancer 10.30.0.125 22.67.23.109 80:30017/TCP,443:31863/TCP 2m58s
38

 
39
# port forward it to local to see the wordpress website
40
$ kubectl port-forward services/my-app-wordpress -n wp 3000:80



Open https://localhost:3000/admin and add a post Post1.


Backup the namespace:

Shell




xxxxxxxxxx
1
50


1
$ velero backup create wp-backup --include-namespaces wp --storage-location azure --wait
2
$ velero get backup
3
NAME STATUS ERRORS WARNINGS CREATED EXPIRES STORAGE LOCATION SELECTOR
4
wp-backup1 Completed 0 0 2021-03-19 20:07:22 +0530 IST 29d azure <none>
5

 
6

 
7
$ velero backup describe wp-backup
8
Name: wp-backup
9
Namespace: velero
10
Labels: velero.io/storage-location=azure
11
Annotations: velero.io/source-cluster-k8s-gitversion=v1.19.3
12
 velero.io/source-cluster-k8s-major-version=1
13
 velero.io/source-cluster-k8s-minor-version=19
14

 
15
Phase: Completed
16

 
17
Errors: 0
18
Warnings: 0
19

 
20
Namespaces:
21
 Included: wp
22
 Excluded: <none>
23

 
24
Resources:
25
 Included: *
26
 Excluded: <none>
27
 Cluster-scoped: auto
28

 
29
Label selector: <none>
30

 
31
Storage Location: azure
32

 
33
Velero-Native Snapshot PVs: auto
34

 
35
TTL: 720h0m0s
36

 
37
Hooks: <none>
38

 
39
Backup Format Version: 1.1.0
40

 
41
Started: 2021-03-19 20:07:22 +0530 IST
42
Completed: 2021-03-19 20:07:26 +0530 IST
43

 
44
Expiration: 2021-04-18 20:07:22 +0530 IST
45

 
46
Total items to be backed up: 50
47
Items backed up: 50
48

 
49
Velero-Native Snapshots: 2
50

 
51

 



Kubernetes objects will be saved under storage account in Azure storage account:

Delete the namespace:

Shell




xxxxxxxxxx
1


1
$ kubectl delete ns wp
2
$ kubectl get pods -n wp
3
No resources found in wp namespace.
4
$ kubectl get pv -A
5
No resources found
6

 



 Restore the namespace using Velero:

Shell




xxxxxxxxxx
1
32


1
$ velero restore create --from-backup wp-backup
2
Restore request "wp-backup-20210319201629" submitted successfully.
3
Run `velero restore describe wp-backup-20210319201629` or `velero restore logs wp-backup-20210319201629` for more details.
4

 
5
$ velero restore describe wp-backup-20210319201629
6
Name: wp-backup-20210319201629
7
Namespace: velero
8
Labels: <none>
9
Annotations: <none>
10

 
11
Phase: Completed
12

 
13
Started: 2021-03-19 20:16:31 +0530 IST
14
Completed: 2021-03-19 20:16:36 +0530 IST
15

 
16
Backup: wp-backup
17

 
18
Namespaces:
19
 Included: all namespaces found in the backup
20
 Excluded: <none>
21

 
22
Resources:
23
 Included: *
24
 Excluded: nodes, events, events.events.k8s.io, backups.velero.io, restores.velero.io, resticrepositories.velero.io
25
 Cluster-scoped: auto
26

 
27
Namespace mappings: <none>
28

 
29
Label selector: <none>
30

 
31
Restore PVs: auto
32

 



Check the restored namespace wp:

Shell




xxxxxxxxxx
1


1
$ kubectl get pods -n wp
2
NAME READY STATUS RESTARTS AGE
3
my-app-mariadb-0 1/1 Running 0 80s
4
my-app-wordpress-75477f4f6c-cj7zk 1/1 Running 0 80s
5

 



Persistent volumes will be restored from the snapshots taken by Velero.

Conclusion 

This article will help you to setup Velero easily on AKS, limiting access to the minimum needed resource group instead of subscription level access.

Kubernetes Docker (software) azure shell

Opinions expressed by DZone contributors are their own.

Related

  • Deploying Containers on Azure Container Apps
  • Cloud Migration: Azure Blob Storage Static Website
  • Keep Your Application Secrets Secret
  • A Comparison of Current Kubernetes Distributions

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

Let's be friends: