Create virtual machines in a Flexible scale set using PowerShell
Applies to: ✔️ Flexible scale sets
This article steps through using PowerShell to create a virtual machine scale set in Flexible orchestration mode. For more information about Flexible scale sets, see Flexible orchestration mode for virtual machine scale sets.
Caution
The orchestration mode is defined when you create the scale set and cannot be changed or updated later.
Launch Azure Cloud Shell
The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.
To open the Cloud Shell, just select Try it from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to https://shell.azure.com/powershell. Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press enter to run it.
Get started with Flexible scale sets
Create a Flexible virtual machine scale set with Azure PowerShell.
Add multiple VMs to a scale set
In the following example, we specify a virtual machine profile (VM type, networking configuration, storage type, etc.) and number of instances to create (sku capacity = 2).
Create IP address configurations:
$ipConfig = New-AzVmssIpConfig -Name "myIPConfig" -SubnetId "${vnetid}/subnets/default" ` -LoadBalancerBackendAddressPoolsId $lb.BackendAddressPools[0].IdCreate a config object:
The config object stores the core information for creating a scale set.
$vmssConfig = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_DS1_v2" -OrchestrationMode 'Flexible' ` -PlatformFaultDomainCount 1Reference a virtual machine image from the gallery:
Set-AzVmssStorageProfile $vmssConfig -OsDiskCreateOption "FromImage" -ImageReferencePublisher "Canonical" -ImageReferenceOffer "UbuntuServer" -ImageReferenceSku "18.04-LTS" ` -ImageReferenceVersion "latest"Set up information for authenticating with the virtual machine:
Set-AzVmssOsProfile $vmssConfig -AdminUsername $cred.UserName -AdminPassword $cred.Password -ComputerNamePrefix $vmnameAttach the virtual network to the config object:
Add-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmssConfig -Name "network-config" -Primary $true -IPConfiguration $ipConfig ` -NetworkApiVersion '2020-11-01'Create the scale set with the config object:
This step might take a few minutes to complete.
New-AzVmss -ResourceGroupName $rgname -Name $vmssName ` -VirtualMachineScaleSet $vmssConfig
Add a single VM to a scale set
The following example shows the creation of a Flexible scale set without a VM profile, where the fault domain count is set to 1. A virtual machine is created and then added to the Flexible scale set.
Log into Azure PowerShell and specify the subscription and variables for the deployment.
Connect-AzAccount Set-AzContext ` -Subscription "00000000-0000-0000-0000-000000000" $loc = "eastus" $rgname = "myResourceGroupFlexible" $vmssName = "myFlexibleVMSS" $vmname = "myFlexibleVM"Do not specify VM Profile parameters like networking or VM SKUs.
$VmssConfigWithoutVmProfile = new-azvmssconfig -location $loc -platformfaultdomain 1 ` $VmssFlex = new-azvmss -resourcegroupname $rgname -vmscalesetname $vmssName -virtualmachinescaleset $VmssConfigWithoutVmProfileAdd a VM to the Flexible scale set.
$vm = new-azvm -resourcegroupname $rgname -location $loc -name $vmname -credential $cred -domainnamelabel $domainName -vmssid $VmssFlex.id
Next steps
Povratne informacije
Pošalјite i prikažite povratne informacije za