你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

快速入门:使用 Bicep 创建 Azure 操作员 Nexus 虚拟机

  • 使用 Bicep 部署 Azure Nexus 虚拟机

本快速入门指南旨在帮助你开始使用 Nexus 虚拟机托管虚拟网络功能 (VNF)。 按照本指南中所述的步骤操作,可以快速轻松地创建满足特定需求和要求的自定义 Nexus 虚拟机。 无论你是 Nexus 网络的初学者还是专家,本指南都可以帮助你。 你将了解创建和自定义用于托管虚拟网络功能的 Nexus 虚拟机所需的全部知识。

开始之前

如果没有 Azure 订阅,请在开始之前创建一个 Azure 免费帐户

  • 安装必需的 Azure CLI 扩展的最新版本。

  • 本文需要 2.49.0 或更高版本的 Azure CLI。 如果使用 Azure Cloud Shell,则最新版本已安装。

  • 如果你有多个 Azure 订阅,请使用 az account 命令选择应在其中计收资源费用的相应订阅 ID。

  • 在继续创建虚拟机之前,请确保根据说明创建要使用的容器映像。

  • 使用 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/deployments 资源类型的所有操作具有访问权限。 例如,若要部署群集,需要 Microsoft.NetworkCloud/virtualMachines/write 和 Microsoft.Resources/deployments/* 权限。 有关角色和权限的列表,请参阅 Azure 内置角色

  • 需要 Azure Operator Nexus 群集的 custom location 资源 ID。

  • 需要根据特定的工作负载要求创建各种网络,并且必须具有适用于工作负载的相应 IP 地址。 为确保顺利实施,建议咨询相关支持团队以获取帮助。

查看模板

在部署虚拟机模板之前,让我们查看内容以了解其结构。

@description('The name of Nexus virtual machine')
param vmName string

@description('The Azure region where the VM is to be deployed')
param location string = resourceGroup().location

@description('The custom location of the Nexus instance')
param extendedLocation string

@description('The metadata tags to be associated with the cluster resource')
param tags object = {}

@description('The name of the administrator to which the ssh public keys will be added into the authorized keys.')
@minLength(1)
@maxLength(32)
param adminUsername string = 'azureuser'

@description('Selects the boot method for the virtual machine.')
@allowed([
  'UEFI'
  'BIOS'
])
param bootMethod string = 'UEFI'

@description('The Cloud Services Network attachment ARM ID to attach to virtual machine.')
param cloudServicesNetworkId string

@description('Number of CPU cores for the virtual machine. Choose a value between 2 and 46.')
param cpuCores int = 2

@description('The memory size of the virtual machine in GB (max 224 GB)')
param memorySizeGB int = 4

@description('The list of network attachments to the virtual machine.')
param networkAttachments array

// {
//   attachedNetworkId: "string"
//   defaultGateway: "True"/"False"
//   ipAllocationMethod: "Dynamic"/"Static","Disabled"
//   ipv4Address: "string"
//   ipv6Address: "string"
//   networkAttachmentName: "string"
// }

@description('The Base64 encoded cloud-init network data.')
param networkData string = ''

@description('The placement hints for the virtual machine.')
param placementHints array = []
// {
//   hintType: "Affinity/AntiAffinity"
//   resourceId: string
//   schedulingExecution: "Hard/Soft"
//   scope: "Rack/Machine"
// }

@description('The list of SSH public keys for the virtual machine.')
param sshPublicKeys array
// {
//   keyData: 'string'
// }

@description('StorageProfile represents information about a disk.')
param storageProfile object = {
  osDisk: {
    createOption: 'Ephemeral'
    deleteOption: 'Delete'
    diskSizeGB: 64
  }
}

@description('The Base64 encoded cloud-init user data.')
param userData string = ''

@description('The type of the device model to use.')
@allowed([
  'T1'
  'T2'
])
param vmDeviceModel string = 'T2'

@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.')
param vmImage string

@description('Credentials used to login to the image repository.')
param vmImageRepositoryCredentials object
// password: "string"
// registryUrl: "string"
// username: "string"

resource vm 'Microsoft.NetworkCloud/virtualMachines@2023-07-01' = {
  name: vmName
  location: location
  extendedLocation: {
    type: 'CustomLocation'
    name: extendedLocation
  }
  tags: tags
  properties: {
    adminUsername: (empty(adminUsername) ? null : adminUsername)
    bootMethod: (empty(bootMethod) ? null : bootMethod)
    cloudServicesNetworkAttachment: {
      attachedNetworkId: cloudServicesNetworkId
      defaultGateway: 'False'
      ipAllocationMethod: 'Dynamic'
    }
    cpuCores: cpuCores
    memorySizeGB: memorySizeGB
    networkData: (empty(networkData) ? null : networkData)
    networkAttachments: (empty(networkAttachments) ? null : networkAttachments)
    placementHints: (empty(placementHints) ? null : placementHints)
    sshPublicKeys: (empty(sshPublicKeys) ? null : sshPublicKeys)
    storageProfile: (empty(storageProfile) ? null : storageProfile)
    userData: (empty(userData) ? null : userData)
    vmDeviceModel: (empty(vmDeviceModel) ? null : vmDeviceModel)
    vmImage: (empty(vmImage) ? null : vmImage)
    vmImageRepositoryCredentials: (empty(vmImageRepositoryCredentials) ? null : vmImageRepositoryCredentials)
  }
}

查看并保存命名 virtual-machine-bicep-template.bicep的模板文件后,请转到下一部分来部署模板。

部署模板

  1. 创建以 JSON 格式命名 virtual-machine-parameters.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-bicep-template.bicep --parameters @virtual-machine-parameters.json

查看已部署的资源

部署完成后,可以使用 CLI 或 Azure 门户查看资源。

若要查看资源组中myResourceGroup群集的详细信息myNexusVirtualMachine,请执行以下操作

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

清理资源

不再需要资源组时,可将其删除。 资源组和资源组中的所有资源都会被删除。

使用 az group delete 命令可删除资源组、虚拟机以及除 Operator Nexus 网络资源外的所有相关资源。

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

后续步骤

已成功创建 Nexus 虚拟机。 现在,可以使用虚拟机托管虚拟网络功能 (VNF)。