共用方式為


快速入門:使用 Azure Resource Manager 範本 (ARM 範本) 建立 Azure 運算子連接點虛擬機器

  • 部署使用 Azure Resource Manager 範本的 Azure 連接點虛擬機器。

本快速入門指南旨在協助您開始使用連接點虛擬機器裝載虛擬網路功能 (VNF)。 透過遵循本指南中概述的步驟,您可以快速輕鬆地建立符合您特定需求和要求的自訂連接點虛擬機器。 無論您是連接點網路的初學者還是專家,本指南都能在此為您提供協助。 您會了解建立和自訂連接點虛擬機器以裝載虛擬網路功能所需的一切資訊。

開始之前

如果您沒有 Azure 訂用帳戶,請在開始之前先建立 Azure 免費帳戶

  • 安裝必要的 Azure CLI 擴充功能最新版。

  • 本文必須使用 Azure CLI 2.49.0 版或更新版本。 如果您是使用 Azure Cloud Shell,就已安裝最新版本。

  • 如果您有多個 Azure 訂用帳戶,則請使用 az account 命令選取應該對資源計費的適當訂用帳戶識別碼。

  • 在繼續建立虛擬機器之前,請確保按照指示建立要使用的容器映像。

  • 使用 az group create 命令建立資源群組。 Azure 資源群組是部署及管理 Azure 資源所在的邏輯群組。 建立資源群組時,系統會提示您指定位置。 此位置是資源群組中繼資料的儲存位置,如果您未在資源建立期間指定另一個區域,此位置也會是您在 Azure 中執行資源的位置。 下列範例會在 eastus 位置建立名為 myResourceGroup 的資源群組。

    az group create --name myResourceGroup --location eastus
    

    下列輸出範例類似於成功建立資源群組:

    {
      "id": "/subscriptions/<guid>/resourceGroups/myResourceGroup",
      "location": "eastus",
      "managedBy": null,
      "name": "myResourceGroup",
      "properties": {
        "provisioningState": "Succeeded"
      },
      "tags": null
    }
    
  • 若要部署 Bicep 檔案或 ARM 範本,您需要對即將進行部署的資源具備寫入存取權,並可存取 Microsoft.Resources/部署資源類型上的所有作業。 例如,若要部署叢集,您需要 Microsoft.NetworkCloud/virtualMachines/write 和 Microsoft.Resources/deployments/* 權限。 如需角色與權限的清單,請參閱 Azure 內建角色

  • 您需要您的 Azure 運算子連接點叢集的 custom location 資源識別碼。

  • 您必須根據特定的工作負載需求建立各種網路,而且必須為您的工作負載提供適當的 IP 位址。 為確保順利實作,建議您諮詢相關的支援小組以取得協助。

檢閱範本

在部署虛擬機範本之前,讓我們先檢閱內容以了解其結構。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string",
            "metadata": {
                "description": "The name of Nexus virtual machine"
            }
        },
        "location": {
            "type": "string",
            "metadata": {
                "description": "The Azure region where the VM is to be deployed"
            },
            "defaultValue": "[resourceGroup().location]"
        },
        "extendedLocation": {
            "type": "string",
            "metadata": {
                "description": "The custom location of the Nexus instance"
            }
        },
        "tags": {
            "type": "object",
            "metadata": {
                "description": "The metadata tags to be associated with the cluster resource"
            },
            "defaultValue": {}
        },
        "adminUsername": {
            "type": "string",
            "defaultValue": "azureuser",
            "maxLength": 32,
            "minLength": 1,
            "metadata": {
                "description": "The name of the administrator to which the ssh public keys will be added into the authorized keys."
            }
        },
        "bootMethod": {
            "type": "string",
            "defaultValue": "UEFI",
            "allowedValues": ["UEFI", "BIOS"],
            "metadata": {
                "description": "Selects the boot method for the virtual machine."
            }
        },
        "cloudServicesNetworkId": {
            "type": "string",
            "metadata": {
                "description": "The Cloud Services Network attachment ARM ID to attach to virtual machine."
            }
        },
        "cpuCores": {
            "type": "int",
            "defaultValue": 2,
            "metadata": {
                "description": "Number of CPU cores for the virtual machine. Choose a value between 2 and 46."
            }
        },
        "memorySizeGB": {
            "type": "int",
            "defaultValue": 4,
            "metadata": {
                "description": "The memory size of the virtual machine in GiB (max 224 GiB)"
            }
        },
        "networkAttachments": {
            "type": "array",
            "metadata": {
                "description": "The list of network attachments to the virtual machine."
            }
            /*
            {
                "attachedNetworkId": "string",
                "defaultGateway": "True"/"False",
                "ipAllocationMethod": "Dynamic"/"Static"/"Disabled",
                "ipv4Address": "string",
                "ipv6Address": "string",
                "networkAttachmentName": "string"
            }
            */
        },
        "networkData": {
            "type": "string",
            "metadata": {
                "description": "The Base64 encoded cloud-init network data."
            },
            "defaultValue": ""
        },
        "placementHints": {
            "type": "array",
            "metadata": {
                "description": "The placement hints for the virtual machine."
            },
            "defaultValue": []
            /*
            {
                "hintType": "Affinity",
                "resourceId": "string",
                "schedulingExecution": "Hard",
                "scope": "Rack"
            }
            */
        },
        "sshPublicKeys": {
            "type": "array",
            "metadata": {
                "description": "The list of SSH public keys for the virtual machine."
            }
            /*
            {
                "keyData": "string"
            }
            */
        },
        "storageProfile": {
            "type": "object",
            "metadata": {
                "description": "StorageProfile represents information about a disk."
            },
            "defaultValue": {
                "osDisk": {
                    "createOption": "Ephemeral",
                    "deleteOption": "Delete",
                    "diskSizeGB": 64
                }
            }
        },
        "userData": {
            "type": "string",
            "metadata": {
                "description": "The Base64 encoded cloud-init user data."
            },
            "defaultValue": ""
        },
        "vmDeviceModel": {
            "type": "string",
            "defaultValue": "T2",
            "allowedValues": ["T1", "T2"],
            "metadata": {
                "description": "The type of the device model to use."
            }
        },
        "vmImage": {
            "type": "string",
            "metadata": {
                "description": "The virtual machine image that is currently provisioned to the OS disk, using the full URL and tag notation used to pull the image."
            }
        },
        "vmImageRepositoryCredentials": {
            "type": "object",
            "metadata": {
                "description": "Credentials used to login to the image repository."
            }
            /*
                "password": "string",
                "registryUrl": "string",
                "username": "string"
            */
        }
    },
    "resources": [
        {
            "type": "Microsoft.NetworkCloud/virtualMachines",
            "apiVersion": "2023-07-01",
            "name": "[parameters('vmName')]",
            "location": "[parameters('location')]",
            "extendedLocation": {
                "type": "CustomLocation",
                "name": "[parameters('extendedLocation')]"
            },
            "tags": "[parameters('tags')]",
            "properties": {
                "adminUsername": "[if(empty(parameters('adminUsername')), json('null'), parameters('adminUsername'))]",
                "bootMethod": "[if(empty(parameters('bootMethod')), json('null'), parameters('bootMethod'))]",
                "cloudServicesNetworkAttachment": {
                    "attachedNetworkId": "[parameters('cloudServicesNetworkId')]",
                    "defaultGateway": "False",
                    "ipAllocationMethod": "Dynamic"
                },
                "cpuCores": "[parameters('cpuCores')]",
                "memorySizeGB": "[parameters('memorySizeGB')]",
                "networkData": "[if(empty(parameters('networkData')), json('null'), parameters('networkData'))]",
                "networkAttachments": "[if(empty(parameters('networkAttachments')), json('null'), parameters('networkAttachments'))]",
                "placementHints": "[if(empty(parameters('placementHints')), json('null'), parameters('placementHints'))]",
                "sshPublicKeys": "[if(empty(parameters('sshPublicKeys')), json('null'), parameters('sshPublicKeys'))]",
                "storageProfile": "[if(empty(parameters('storageProfile')), json('null'), parameters('storageProfile'))]",
                "userData": "[if(empty(parameters('userData')), json('null'), parameters('userData'))]",
                "vmDeviceModel": "[if(empty(parameters('vmDeviceModel')), json('null'), parameters('vmDeviceModel'))]",
                "vmImage": "[if(empty(parameters('vmImage')), json('null'), parameters('vmImage'))]",
                "vmImageRepositoryCredentials": "[if(empty(parameters('vmImageRepositoryCredentials')), json('null'), parameters('vmImageRepositoryCredentials'))]"
            }
        }
    ]
  }

檢閱並儲存名為 virtual-machine-arm-template.json的範本檔案之後,請繼續進行至下一小節以部署範本。

部署範本

  1. 建立名為 virtual-machine-parameters.json 的檔案,並以 JSON 格式新增必要的參數。 您可以使用下列範例做為起點。 使用您自己的值加以取代。
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "vmName": {
        "value": "myNexusVirtualMachine"
      },
      "location": {
        "value": "eastus"
      },
      "extendedLocation": {
        "value": "/subscriptions/<subscription>/resourcegroups/<cluster-managed-resource-group>/providers/microsoft.extendedlocation/customlocations/<custom-location-name>"
      },
      "cloudServicesNetworkId": {
          "value": "/subscriptions/<subscription>/resourceGroups/<network-resource-group>/providers/Microsoft.NetworkCloud/cloudServicesNetworks/<csn-name>"
      },
      "networkAttachments": {
          "value": [
            {
                "attachedNetworkId": "/subscriptions/<subscription>/resourceGroups/<network-resource-group>/providers/Microsoft.NetworkCloud/l3Networks/<l3network-name>",
                "ipAllocationMethod": "Dynamic",
                "defaultGateway": "True",
                "networkAttachmentName": "mgmt0"
            }
        ]
      },
      "sshPublicKeys": {
          "value": [
            {
                "keyData": "ssh-rsa AAAAB3...."
            }
        ]
      },
      "vmImage": {
          "value": "<Image ACR URL>"
      },
      "vmImageRepositoryCredentials": {
          "value": {
              "password": "********************",
              "registryUrl": "<ACR registry URL>",
              "username": "<ACR user name>"
          }
      }
    }
  }
  1. 部署範本。
    az deployment group create --resource-group myResourceGroup --template-file virtual-machine-arm-template.json --parameters @virtual-machine-parameters.json

檢閱已部署的資源

部署完成之後,您可以使用 CLI 或 Azure 入口網站檢視資源。

若要檢視 myResourceGroup 資源群組中 myNexusVirtualMachine 叢集的詳細資料,請執行下列命令

az networkcloud virtualmachine show --name myNexusVirtualMachine --resource-group myResourceGroup

清除資源

不再需要資源群組時,請加以刪除。 資源群組和資源群組中的所有資源都會被刪除。

使用 az group delete 命令移除資源群組、虛擬機器,以及運算子連接點網路資源以外的所有相關資源。

az group delete --name myResourceGroup --yes --no-wait

下一步

您已成功建立連接點虛擬機器。 您現在可以使用虛擬機器裝載虛擬網路功能 (VNF)。