次の方法で共有


クイックスタート: Azure Bicep を使用して Azure Kubernetes Service (AKS) クラスターのコンテナー バックアップを構成する

このクイックスタートでは、Azure Bicep を使用して Azure Kubernetes Service (AKS) クラスターのコンテナー バックアップを構成する方法について説明します。

Azure Backup for AKS は、AKS クラスターのバックアップをすばやく構成できる、クラウドネイティブでエンタープライズ対応のアプリケーション中心のバックアップ サービスです。Azure Backup では、Azure portal、PowerShell、CLI、Azure Resource Manager、Bicep などの複数のオプションを使用して、AKS クラスターをバックアップできます。 このクイックスタートでは、Bicep ファイルと Azure PowerShell を使用して AKS クラスターをバックアップする方法について説明します。 Bicep ファイルの開発の詳細については、 Bicep のドキュメントを参照してください

Bicep は、Azure リソースを宣言によってデプロイするための言語です。 JSON の代わりに Bicep を使用して、Azure Resource Manager テンプレート (ARM テンプレート) を開発できます。 Bicep の構文により複雑さが軽減され、開発エクスペリエンスが向上します。 Bicep は ARM テンプレート JSON に対する透過的な抽象化であり、JSON テンプレートのすべての機能が提供されます。 デプロイ中に、Bicep CLI により、Bicep ファイルが ARM テンプレート JSON に変換されます。 Bicep ファイルでは、リソースを作成するための一連のプログラミング コマンドを記述せずに、Azure リソースとリソース プロパティを記述します。

ARM テンプレートで有効なリソースの種類、API バージョン、およびプロパティは、Bicep ファイルでも有効です。

前提条件

Bicep の開発環境を設定するには、「Bicep ツールをインストールする」を参照してください。

記事で詳細に説明されているように、最新の Azure PowerShell モジュールと Bicep CLI をインストールします。

テンプレートを確認する

このテンプレートを使用すると、AKS クラスターのバックアップを構成できます。 このテンプレートでは、AKS クラスターのバックアップ ポリシーを含むバックアップ コンテナーを作成し、"4 時間ごと" のスケジュールと、"7 日間" のリテンション期間を設定します。

@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

テンプレートのデプロイ

このテンプレートをデプロイするには、GitHub または任意の場所に格納し、シェル ウィンドウに次の PowerShell スクリプトを貼り付けます。 コードを貼り付けるには、シェル ウィンドウを右クリックして、 [貼り付け] を選択します。

$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 

次のステップ