新增自訂映像至 Azure 擴展集範本
注意
本文件涵蓋以統一協調流程模式執行的虛擬機器擴展集。 我們建議針對新的工作負載使用彈性協調流程。 如需詳細資訊,請參閱 Azure 中虛擬機器擴展集的協調流程模式。
本文說明如何修改基本擴展集範本,以透過自訂映像進行部署。
變更範本定義
在上一篇文章中,我們建立了基本的擴展集範本。 我們現在會使用先前的範本並加以修改,以建立可透過自訂映像部署擴展集的範本。
建立受控磁碟映像
如果您已有自訂的受控磁碟映像 (類型為 Microsoft.Compute/images
的資源),則可略過此節。
首先,新增 sourceImageVhdUri
參數,這是 Azure 儲存體中包含所要部署自訂映像的一般化 blob 其 URI。
},
"adminPassword": {
"type": "securestring"
+ },
+ "sourceImageVhdUri": {
+ "type": "string",
+ "metadata": {
+ "description": "The source of the generalized blob containing the custom image"
+ }
}
},
"variables": {},
接著,新增類型為 Microsoft.Compute/images
的資源,這是以位在 URI sourceImageVhdUri
的一般化 blob 為基礎的受控磁碟映像。 此映像必須位在與使用它的擴展集相同的區域中。 在映像的屬性中,指定作業系統類型、blob 的位置 (從 sourceImageVhdUri
參數) 及儲存體帳戶類型:
"resources": [
{
+ "type": "Microsoft.Compute/images",
+ "apiVersion": "2019-03-01",
+ "name": "myCustomImage",
+ "location": "[resourceGroup().location]",
+ "properties": {
+ "storageProfile": {
+ "osDisk": {
+ "osType": "Linux",
+ "osState": "Generalized",
+ "blobUri": "[parameters('sourceImageVhdUri')]",
+ "storageAccountType": "Standard_LRS"
+ }
+ }
+ }
+ },
+ {
"type": "Microsoft.Network/virtualNetworks",
"name": "myVnet",
"location": "[resourceGroup().location]",
在擴展集資源中,新增參照自訂映像的 dependsOn
子句,以確定會先建立映像,擴展集才會嘗試從該映像部署:
"location": "[resourceGroup().location]",
"apiVersion": "2019-03-01-preview",
"dependsOn": [
- "Microsoft.Network/virtualNetworks/myVnet"
+ "Microsoft.Network/virtualNetworks/myVnet",
+ "Microsoft.Compute/images/myCustomImage"
],
"sku": {
"name": "Standard_A1",
變更擴展集屬性以使用受控磁碟映像
在擴展集 storageProfile
的 imageReference
中,不是指定發行者、供應項目、sku 及平台映像版本,而是指定 Microsoft.Compute/images
資源的 id
:
"virtualMachineProfile": {
"storageProfile": {
"imageReference": {
"id": "[resourceId('Microsoft.Compute/images', omImage')]"
}
},
"osProfile": {
...
}
}
在此範例中,使用 resourceId
函式取得以相同範本所建立映像的資源識別碼。 如果您已事先建立受控磁碟映像,您應改為提供該映像的識別碼。 此識別碼的格式必須是:/subscriptions/<subscription-id>resourceGroups/<resource-group-name>/providers/Microsoft.Compute/images/<image-name>
。
後續步驟
您可以依照 Azure Resource Manager 文件所述來部署上述範本。
本教學課程系列可從基本的擴展集範本文章開始。
您可了解如何修改基本的擴展集範本,以將擴展集部署至現有虛擬網路。
您可了解如何修改基本的擴展集範本,以使用自訂映像部署擴展集。
您可了解如何修改基本的擴展集範本,以使用來賓型自動調整來部署 Linux 擴展集。
如需擴展集的詳細資訊,請參考擴展集概觀頁面。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應