Delen via


Quickstart: Een gekluisde back-up configureren voor een AKS-cluster (Azure Kubernetes Service) met behulp van Azure Bicep

In deze quickstart wordt beschreven hoe u een gekluisde back-up configureert voor een AKS-cluster (Azure Kubernetes Service) met behulp van Azure Bicep.

Azure Backup voor AKS is een cloudeigen, bedrijfsklare, toepassingsgerichte back-upservice waarmee u snel back-ups voor AKS-clusters kunt configureren.Met Azure Backup kunt u een back-up maken van uw AKS-clusters met meerdere opties, zoals Azure Portal, PowerShell, CLI, Azure Resource Manager, Bicep, enzovoort. In deze quickstart wordt beschreven hoe u een back-up maakt van AKS-clusters met een Bicep-bestand en Azure PowerShell. Zie de Bicep-documentatie voor meer informatie over het ontwikkelen van Bicep-bestanden.

Bicep is een taal voor het declaratief implementeren van Azure-resources. U kunt Bicep gebruiken in plaats van JSON om uw Azure Resource Manager-sjablonen (ARM-sjablonen) te ontwikkelen. Bicep-syntaxis vermindert de complexiteit en verbetert de ontwikkelervaring. Bicep is een transparante abstractie van ARM-sjabloon JSON die alle mogelijkheden van JSON-sjablonen biedt. Tijdens de implementatie converteert bicep CLI een Bicep-bestand naar een ARM-sjabloon-JSON. In een Bicep-bestand worden de Azure-resources en resource-eigenschappen vermeld, zonder een reeks programmeeropdrachten te schrijven om resources te maken.

Resourcetypen, API-versies en eigenschappen die geldig zijn in een ARM-sjabloon, zijn ook geldig in een Bicep-bestand.

Vereisten

Zie Bicep-hulpprogramma's installeren om uw omgeving in te stellen voor Bicep-ontwikkeling.

Notitie

Installeer de nieuwste Azure PowerShell-module en de Bicep CLI, zoals beschreven in het artikel.

De sjabloon controleren

Met deze sjabloon kunt u back-ups configureren voor een AKS-cluster. In deze sjabloon maken we een back-upkluis met een back-upbeleid voor het AKS-cluster met een schema van vier uur en een retentieduur van zeven dagen .

@description('Location for the resource group')
param resourceGroupLocation string
@description('Name of the resource group for AKS and Backup Vault')
param resourceGroupName string
@description('Name of the resource group for storage account and snapshots')
param backupResourceGroupName string
@description('Location for the backup resource group')
param backupResourceGroupLocation string
@description('AKS Cluster name')
param aksClusterName string
@description('DNS prefix for AKS')
param dnsPrefix string
@description('Node count for the AKS Cluster')
param nodeCount int
@description('Name of the Backup Vault')
param backupVaultName string
@description('Datastore type for the Backup Vault')
param datastoreType string
@description('Redundancy type for the Backup Vault')
param redundancy string
@description('Backup policy name')
param backupPolicyName string
@description('Name of the Backup Extension')
param backupExtensionName string
@description('Type of Backup Extension')
param backupExtensionType string
@description('Name of the Storage Account')
param storageAccountName string

var backupContainerName = 'tfbackup'

resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
  location: resourceGroupLocation
  name: resourceGroupName
}

resource backupRg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
  location: backupResourceGroupLocation
  name: backupResourceGroupName
}

resource aksCluster 'Microsoft.ContainerService/managedClusters@2023-05-01' = {
  location: resourceGroupLocation
  name: aksClusterName
  properties: {
    dnsPrefix: dnsPrefix
    agentPoolProfiles: [
      {
        name: 'agentpool'
        count: nodeCount
        vmSize: 'Standard_D2_v2'
        type: 'VirtualMachineScaleSets'
        mode: 'System'
      }
    ]
    identity: {
      type: 'SystemAssigned'
    }
    networkProfile: {
      networkPlugin: 'kubenet'
      loadBalancerSku: 'standard'
    }
  }
  dependsOn: [
    rg
    backupRg
  ]
}

resource backupVault 'Microsoft.DataProtection/backupVaults@2023-01-01' = {
  location: resourceGroupLocation
  name: backupVaultName
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    dataStoreType: datastoreType
    redundancy: redundancy
  }
  dependsOn: [
    aksCluster
  ]
}

resource backupPolicy 'Microsoft.DataProtection/backupVaults/backupPolicies@2023-01-01' = {
  name: '${backupVaultName}/${backupPolicyName}'
  properties: {
    backupRepeatingTimeIntervals: ['R/2024-04-14T06:33:16+00:00/PT4H']
    defaultRetentionRule: {
      lifeCycle: {
        duration: 'P7D'
        dataStoreType: 'OperationalStore'
      }
    }
  }
  dependsOn: [
    backupVault
  ]
}

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
  location: backupResourceGroupLocation
  name: storageAccountName
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  dependsOn: [
    aksCluster
  ]
}

resource backupContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2021-04-01' = {
  name: '${storageAccount.name}/default/${backupContainerName}'
  properties: {
    publicAccess: 'None'
  }
  dependsOn: [
    storageAccount
  ]
}

resource backupExtension 'Microsoft.KubernetesConfiguration/extensions@2023-05-01' = {
  name: '${aksClusterName}/${backupExtensionName}'
  properties: {
    extensionType: backupExtensionType
    configurationSettings: {
      'configuration.backupStorageLocation.bucket': backupContainerName
      'configuration.backupStorageLocation.config.storageAccount': storageAccountName
      'configuration.backupStorageLocation.config.resourceGroup': backupResourceGroupName
      'configuration.backupStorageLocation.config.subscriptionId': subscription().subscriptionId
      'credentials.tenantId': subscription().tenantId
    }
  }
  dependsOn: [
    backupContainer
  ]
}

output aksClusterId string = aksCluster.id
output backupVaultId string = backupVault.id

De sjabloon implementeren

Als u deze sjabloon wilt implementeren, slaat u deze op in GitHub of de gewenste locatie en plakt u vervolgens het volgende PowerShell-script in het shell-venster. Als u de code wilt plakken, klikt u met de rechtermuisknop op het shell-venster en selecteert u Plakken.

$projectName = Read-Host -Prompt "Enter a project name (limited to eight characters) that is used to generate Azure resource names"
$location = Read-Host -Prompt "Enter the location (for example, centralus)"

$resourceGroupName = "${projectName}rg"
$templateUri = "templateURI"

New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -projectName $projectName 

Volgende stappen