|
| 1 | +--- |
| 2 | +title: Create a scale set from a generalized image |
| 3 | +description: Create a scale set using a generalized image in a Shared Image Gallery. |
| 4 | +author: cynthn |
| 5 | +ms.service: virtual-machine-scale-sets |
| 6 | +ms.subservice: imaging |
| 7 | +ms.workload: infrastructure-services |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 05/04/2020 |
| 10 | +ms.author: cynthn |
| 11 | +ms.reviewer: akjosh |
| 12 | +--- |
| 13 | + |
| 14 | +# Create a scale set from a generalized image |
| 15 | + |
| 16 | +Create a VM from a generalized image version stored in a [Shared Image Gallery](shared-image-galleries.md). If want to create a scale set using a specialized image, see [Create scale set instances from a specialized image](instance-specialized-image-version-powershell.md). |
| 17 | + |
| 18 | +Once you have a generalized image, you can create a virtual machine scale set using the [New-AzVmss](/powershell/module/az.compute/new-azvmss) cmdlet. |
| 19 | + |
| 20 | +In this example, we are using the image definition ID to ensure your new VM will use the most recent version of an image. You can also use a specific version by using the image version ID for `-ImageReferenceId`. For example, to use image version *1.0.0* type: `-ImageReferenceId "/subscriptions/<subscription ID where the gallery is located>/resourceGroups/myGalleryRG/providers/Microsoft.Compute/galleries/myGallery/images/myImageDefinition/versions/1.0.0"`. |
| 21 | + |
| 22 | +Be aware that using a specific image version means automation could fail if that specific image version isn't available because it was deleted or removed from the region. We recommend using the image definition ID for creating your new VM, unless a specific image version is required. |
| 23 | + |
| 24 | + |
| 25 | +The following examples create a scale set named *myScaleSet*, in the *myVMSSRG* resource group, in the *SouthCentralUS* location. The scale set will be created from the *myImageDefinition* image, in the *myGallery* image gallery in the *myGalleryRG* resource group. When prompted, set your own administrative credentials for the VM instances in the scale set. |
| 26 | + |
| 27 | + |
| 28 | +## Simplified parameter set |
| 29 | + |
| 30 | +To quickly create a scale set, while providing minimal information, use the simplified parameter set to create a scale set from a Share Image Gallery image. |
| 31 | + |
| 32 | +```azurepowershell-interactive |
| 33 | +$imageDefinition = Get-AzGalleryImageDefinition ` |
| 34 | + -GalleryName myGallery ` |
| 35 | + -ResourceGroupName myGalleryRG ` |
| 36 | + -Name myImageDefinition |
| 37 | +
|
| 38 | +# Create user object |
| 39 | +
|
| 40 | +$cred = Get-Credential ` |
| 41 | + -Message "Enter a username and password for the virtual machine." |
| 42 | +
|
| 43 | +# Create the resource group and scale set |
| 44 | +New-AzResourceGroup -ResourceGroupName myVMSSRG -Location SouthCentralUS |
| 45 | +New-AzVmss ` |
| 46 | + -Credential $cred ` |
| 47 | + -VMScaleSetName myScaleSet ` |
| 48 | + -ImageName $imageDefinition.Id ` |
| 49 | + -UpgradePolicyMode Automatic ` |
| 50 | + -ResourceGroupName myVMSSRG |
| 51 | +``` |
| 52 | + |
| 53 | +It takes a few minutes to create and configure all the scale set resources and VMs. |
| 54 | + |
| 55 | +## Extended parameter set |
| 56 | + |
| 57 | +For full control over all of the resources, including naming, use the full parameter set to create a scale set using a Shared Image Gallery image. |
| 58 | + |
| 59 | +```azurepowershell-interactive |
| 60 | +# Get the image definition |
| 61 | +
|
| 62 | +$imageDefinition = Get-AzGalleryImageDefinition ` |
| 63 | + -GalleryName myGallery ` |
| 64 | + -ResourceGroupName myGalleryRG ` |
| 65 | + -Name myImageDefinition |
| 66 | +
|
| 67 | +# Create user object |
| 68 | +
|
| 69 | +$cred = Get-Credential ` |
| 70 | + -Message "Enter a username and password for the virtual machine." |
| 71 | + |
| 72 | +# Define variables for the scale set |
| 73 | +$resourceGroupName = "myVMSSRG" |
| 74 | +$scaleSetName = "myScaleSet" |
| 75 | +$location = "South Central US" |
| 76 | +
|
| 77 | +# Create a resource group |
| 78 | +New-AzResourceGroup -ResourceGroupName $resourceGroupName -Location $location |
| 79 | +
|
| 80 | +# Create a networking pieces |
| 81 | +$subnet = New-AzVirtualNetworkSubnetConfig ` |
| 82 | + -Name "mySubnet" ` |
| 83 | + -AddressPrefix 10.0.0.0/24 |
| 84 | +$vnet = New-AzVirtualNetwork ` |
| 85 | + -ResourceGroupName $resourceGroupName ` |
| 86 | + -Name "myVnet" ` |
| 87 | + -Location $location ` |
| 88 | + -AddressPrefix 10.0.0.0/16 ` |
| 89 | + -Subnet $subnet |
| 90 | +$publicIP = New-AzPublicIpAddress ` |
| 91 | + -ResourceGroupName $resourceGroupName ` |
| 92 | + -Location $location ` |
| 93 | + -AllocationMethod Static ` |
| 94 | + -Name "myPublicIP" |
| 95 | +$frontendIP = New-AzLoadBalancerFrontendIpConfig ` |
| 96 | + -Name "myFrontEndPool" ` |
| 97 | + -PublicIpAddress $publicIP |
| 98 | +$backendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name "myBackEndPool" |
| 99 | +$inboundNATPool = New-AzLoadBalancerInboundNatPoolConfig ` |
| 100 | + -Name "myRDPRule" ` |
| 101 | + -FrontendIpConfigurationId $frontendIP.Id ` |
| 102 | + -Protocol TCP ` |
| 103 | + -FrontendPortRangeStart 50001 ` |
| 104 | + -FrontendPortRangeEnd 50010 ` |
| 105 | + -BackendPort 3389 |
| 106 | +# Create the load balancer and health probe |
| 107 | +$lb = New-AzLoadBalancer ` |
| 108 | + -ResourceGroupName $resourceGroupName ` |
| 109 | + -Name "myLoadBalancer" ` |
| 110 | + -Location $location ` |
| 111 | + -FrontendIpConfiguration $frontendIP ` |
| 112 | + -BackendAddressPool $backendPool ` |
| 113 | + -InboundNatPool $inboundNATPool |
| 114 | +Add-AzLoadBalancerProbeConfig -Name "myHealthProbe" ` |
| 115 | + -LoadBalancer $lb ` |
| 116 | + -Protocol TCP ` |
| 117 | + -Port 80 ` |
| 118 | + -IntervalInSeconds 15 ` |
| 119 | + -ProbeCount 2 |
| 120 | +Add-AzLoadBalancerRuleConfig ` |
| 121 | + -Name "myLoadBalancerRule" ` |
| 122 | + -LoadBalancer $lb ` |
| 123 | + -FrontendIpConfiguration $lb.FrontendIpConfigurations[0] ` |
| 124 | + -BackendAddressPool $lb.BackendAddressPools[0] ` |
| 125 | + -Protocol TCP ` |
| 126 | + -FrontendPort 80 ` |
| 127 | + -BackendPort 80 ` |
| 128 | + -Probe (Get-AzLoadBalancerProbeConfig -Name "myHealthProbe" -LoadBalancer $lb) |
| 129 | +Set-AzLoadBalancer -LoadBalancer $lb |
| 130 | +
|
| 131 | +# Create IP address configurations |
| 132 | +$ipConfig = New-AzVmssIpConfig ` |
| 133 | + -Name "myIPConfig" ` |
| 134 | + -LoadBalancerBackendAddressPoolsId $lb.BackendAddressPools[0].Id ` |
| 135 | + -LoadBalancerInboundNatPoolsId $inboundNATPool.Id ` |
| 136 | + -SubnetId $vnet.Subnets[0].Id |
| 137 | +
|
| 138 | +# Create a configuration |
| 139 | +$vmssConfig = New-AzVmssConfig ` |
| 140 | + -Location $location ` |
| 141 | + -SkuCapacity 2 ` |
| 142 | + -SkuName "Standard_DS2" ` |
| 143 | + -UpgradePolicyMode "Automatic" |
| 144 | +
|
| 145 | +# Reference the image version |
| 146 | +Set-AzVmssStorageProfile $vmssConfig ` |
| 147 | + -OsDiskCreateOption "FromImage" ` |
| 148 | + -ImageReferenceId $imageDefinition.Id |
| 149 | +
|
| 150 | +# Complete the configuration |
| 151 | +Set-AzVmssOsProfile $vmssConfig ` |
| 152 | + -AdminUsername $cred.UserName ` |
| 153 | + -AdminPassword $cred.Password ` |
| 154 | + -ComputerNamePrefix "myVM" |
| 155 | +Add-AzVmssNetworkInterfaceConfiguration ` |
| 156 | + -VirtualMachineScaleSet $vmssConfig ` |
| 157 | + -Name "network-config" ` |
| 158 | + -Primary $true ` |
| 159 | + -IPConfiguration $ipConfig |
| 160 | +
|
| 161 | +# Create the scale set |
| 162 | +New-AzVmss ` |
| 163 | + -ResourceGroupName $resourceGroupName ` |
| 164 | + -Name $scaleSetName ` |
| 165 | + -VirtualMachineScaleSet $vmssConfig |
| 166 | +``` |
| 167 | + |
| 168 | +It takes a few minutes to create and configure all the scale set resources and VMs. |
| 169 | + |
| 170 | +## Next steps |
| 171 | +[Azure Image Builder (preview)](../virtual-machines/linux/image-builder-overview.md) can help automate image version creation, you can even use it to update and [create a new image version from an existing image version](../virtual-machines/linux/image-builder-gallery-update-image-version.md). |
| 172 | + |
| 173 | +You can also create Shared Image Gallery resource using templates. There are several Azure Quickstart Templates available: |
| 174 | + |
| 175 | +- [Create a Shared Image Gallery](https://azure.microsoft.com/resources/templates/101-sig-create/) |
| 176 | +- [Create an Image Definition in a Shared Image Gallery](https://azure.microsoft.com/resources/templates/101-sig-image-definition-create/) |
| 177 | +- [Create an Image Version in a Shared Image Gallery](https://azure.microsoft.com/resources/templates/101-sig-image-version-create/) |
| 178 | + |
| 179 | +For more information about Shared Image Galleries, see the [Overview](shared-image-galleries.md). If you run into issues, see [Troubleshooting shared image galleries](troubleshooting-shared-images.md). |
0 commit comments