To create the Backup vault, run the following command:
Azure CLI
az dataprotection backup-vault create --resource-group$backupvaultresourcegroup--vault-name$backupvault--location$region--type SystemAssigned --storage-settingsdatastore-type="VaultStore"type="GloballyRedundant"
The newly created vault has storage settings set as Globally Redundant, thus backups stored in vault tier will be available in the Azure paired region. Once the vault creation is complete, create a backup policy to protect AKS clusters.
Create a backup policy
Retrieve the policy template using the command az dataprotection backup-policy get-default-policy-template.
Azure CLI
az dataprotection backup-policy get-default-policy-template --datasource-type AzureKubernetesService > akspolicy.json
We update the default template for the backup policy and add a retention rule to retain first successful backup per day in the Vault tier for 30 days.
Azure CLI
az dataprotection backup-policy retention-rule create-lifecycle --count30--retention-duration-type Days --copy-option ImmediateCopyOption --target-datastore VaultStore --source-datastore OperationalStore > ./retentionrule.json
az dataprotection backup-policy retention-rule set --lifecycles ./retentionrule.json --name Daily --policy ./akspolicy.json > ./akspolicy.json
Once the policy JSON has all the required values, proceed to create a new policy from the policy object.
Once the vault and policy creation are complete, you need to perform the following prerequisites to get the AKS cluster ready for backup:
Create a storage account and blob container.
Backup for AKS stores Kubernetes resources in a blob container as backups. To get the AKS cluster ready for backup, you need to install an extension in the cluster. This extension requires the storage account and blob container as inputs.
To create a new storage account, run the following command:
Azure CLI
az storage account create --name$storageaccount--resource-group$storageaccountresourcegroup--location$region--sku Standard_LRS
Once the storage account creation is complete, create a blob container inside by running the following command:
Azure CLI
az storage container create --name$blobcontainer--account-name$storageaccount--auth-mode login
Install Backup Extension.
Backup Extension is mandatory to be installed in the AKS cluster to perform any backup and restore operations. The Backup Extension creates a namespace dataprotection-microsoft in the cluster and uses the same to deploy its resources. The extension requires the storage account and blob container as inputs for installation.
As part of extension installation, a user identity is created in the AKS cluster's Node Pool Resource Group. For the extension to access the storage account, you need to provide this identity the Storage Blob Data Contributor role. To assign the required role, run the following command:
Azure CLI
az role assignment create --assignee-object-id $(az k8s-extension show --name azure-aks-backup--cluster-name$akscluster--resource-group$aksclusterresourcegroup--cluster-type managedClusters --query aksAssignedIdentity.principalId --output tsv) --role'Storage Blob Data Contributor'--scope /subscriptions/$subscriptionId/resourceGroups/$storageaccountresourcegroup/providers/Microsoft.Storage/storageAccounts/$storageaccount
Enable Trusted Access
For the Backup vault to connect with the AKS cluster, you must enable Trusted Access as it allows the Backup vault to have a direct line of sight to the AKS cluster.
To enable Trusted Access, run the following command:
Azure CLI
az aks trustedaccess rolebinding create --cluster-name$akscluster--name backuprolebinding --resource-group$aksclusterresourcegroup--roles Microsoft.DataProtection/backupVaults/backup-operator--source-resource-id /subscriptions/$subscriptionId/resourceGroups/$backupvaultresourcegroup/providers/Microsoft.DataProtection/BackupVaults/$backupvault
Configure vaulted backups for AKS cluster
With the created Backup vault and backup policy, and the AKS cluster in ready-to-be-backed-up state, you can now start to back up your AKS cluster.
Prepare the request
The configuration of backup is performed in two steps:
Prepare backup configuration to define which cluster resources are to be backed up using the az dataprotection backup-instance initialize-backupconfig command. The command generates a JSON, which you can update to define backup configuration for your AKS cluster as required.
Azure CLI
az dataprotection backup-instance initialize-backupconfig --datasource-type AzureKubernetesService > aksbackupconfig.json
Prepare the relevant request using the relevant vault, policy, AKS cluster, backup configuration, and snapshot resource group using the az dataprotection backup-instance initialize command.
Use Azure Policy to enforce policies and safeguards on your Kubernetes clusters at scale. Azure Policy Ensures that your cluster is secure, compliant, and consistent across your organization.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.