How to create a VM scale set from a Snapshot
I want to create a VM Scale set and use a snapshot as base for my windows VMs. As the Set-AzureRmVmssStorageProfile only accepts images my first try was to convert the snapshot to an image by use:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -SnapshotId $snapshot.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
But in this case the image that is created has no Source Blob URI:
what gives me the error:
New-AzureRmVmss : The URI Microsoft.Azure.Commands.Compute.Automation.Models.PSImage does not look to be correct blob URI.
On my deploy commands for azure:
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" `
-Image $ImgRef -OsDiskOsType Windows -OsDiskName "C"
Set-AzureRmVmssOSProfile -ComputerNamePrefix $vmNamePrefix -AdminUsername $adminUsername -AdminPassword $adminPassword -VirtualMachineScaleSet $vmss
New-AzureRmVmss -ResourceGroupName $currentrg -Name $vmssName -VirtualMachineScaleSet $vmss -Verbose -ErrorAction Stop;
Is there a other way to create the image or set a source blob uri?
Or is it possible to use a snapshot for creating an VM Scale Set?
-- Edit 1 --
Afer the hint from Charles Xu I changhed the image creation to first create a dik, but I still get the same error. New Code is:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$storageType = 'Standard_LRS'
$diskName = "myDisk"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $rgName -DiskName $diskName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -ManagedDiskId $disk.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
azure azure-devops azure-powershell azure-vm-scale-set
add a comment |
I want to create a VM Scale set and use a snapshot as base for my windows VMs. As the Set-AzureRmVmssStorageProfile only accepts images my first try was to convert the snapshot to an image by use:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -SnapshotId $snapshot.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
But in this case the image that is created has no Source Blob URI:
what gives me the error:
New-AzureRmVmss : The URI Microsoft.Azure.Commands.Compute.Automation.Models.PSImage does not look to be correct blob URI.
On my deploy commands for azure:
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" `
-Image $ImgRef -OsDiskOsType Windows -OsDiskName "C"
Set-AzureRmVmssOSProfile -ComputerNamePrefix $vmNamePrefix -AdminUsername $adminUsername -AdminPassword $adminPassword -VirtualMachineScaleSet $vmss
New-AzureRmVmss -ResourceGroupName $currentrg -Name $vmssName -VirtualMachineScaleSet $vmss -Verbose -ErrorAction Stop;
Is there a other way to create the image or set a source blob uri?
Or is it possible to use a snapshot for creating an VM Scale Set?
-- Edit 1 --
Afer the hint from Charles Xu I changhed the image creation to first create a dik, but I still get the same error. New Code is:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$storageType = 'Standard_LRS'
$diskName = "myDisk"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $rgName -DiskName $diskName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -ManagedDiskId $disk.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
azure azure-devops azure-powershell azure-vm-scale-set
add a comment |
I want to create a VM Scale set and use a snapshot as base for my windows VMs. As the Set-AzureRmVmssStorageProfile only accepts images my first try was to convert the snapshot to an image by use:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -SnapshotId $snapshot.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
But in this case the image that is created has no Source Blob URI:
what gives me the error:
New-AzureRmVmss : The URI Microsoft.Azure.Commands.Compute.Automation.Models.PSImage does not look to be correct blob URI.
On my deploy commands for azure:
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" `
-Image $ImgRef -OsDiskOsType Windows -OsDiskName "C"
Set-AzureRmVmssOSProfile -ComputerNamePrefix $vmNamePrefix -AdminUsername $adminUsername -AdminPassword $adminPassword -VirtualMachineScaleSet $vmss
New-AzureRmVmss -ResourceGroupName $currentrg -Name $vmssName -VirtualMachineScaleSet $vmss -Verbose -ErrorAction Stop;
Is there a other way to create the image or set a source blob uri?
Or is it possible to use a snapshot for creating an VM Scale Set?
-- Edit 1 --
Afer the hint from Charles Xu I changhed the image creation to first create a dik, but I still get the same error. New Code is:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$storageType = 'Standard_LRS'
$diskName = "myDisk"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $rgName -DiskName $diskName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -ManagedDiskId $disk.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
azure azure-devops azure-powershell azure-vm-scale-set
I want to create a VM Scale set and use a snapshot as base for my windows VMs. As the Set-AzureRmVmssStorageProfile only accepts images my first try was to convert the snapshot to an image by use:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -SnapshotId $snapshot.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
But in this case the image that is created has no Source Blob URI:
what gives me the error:
New-AzureRmVmss : The URI Microsoft.Azure.Commands.Compute.Automation.Models.PSImage does not look to be correct blob URI.
On my deploy commands for azure:
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" `
-Image $ImgRef -OsDiskOsType Windows -OsDiskName "C"
Set-AzureRmVmssOSProfile -ComputerNamePrefix $vmNamePrefix -AdminUsername $adminUsername -AdminPassword $adminPassword -VirtualMachineScaleSet $vmss
New-AzureRmVmss -ResourceGroupName $currentrg -Name $vmssName -VirtualMachineScaleSet $vmss -Verbose -ErrorAction Stop;
Is there a other way to create the image or set a source blob uri?
Or is it possible to use a snapshot for creating an VM Scale Set?
-- Edit 1 --
Afer the hint from Charles Xu I changhed the image creation to first create a dik, but I still get the same error. New Code is:
$rgName = #...
$location = #...
$snapshotName = "mySnapshot"
$imageName = "myImage"
$storageType = 'Standard_LRS'
$diskName = "myDisk"
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $rgName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -AccountType $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $rgName -DiskName $diskName
$imageConfig = New-AzureRmImageConfig -Location $location
$imageConfig = Set-AzureRmImageOsDisk -Image $imageConfig -OsState Generalized -OsType Windows -ManagedDiskId $disk.Id
New-AzureRmImage -ImageName $imageName -ResourceGroupName $rgName -Image $imageConfig
azure azure-devops azure-powershell azure-vm-scale-set
azure azure-devops azure-powershell azure-vm-scale-set
edited Nov 26 '18 at 8:30
Daniel W.
asked Nov 26 '18 at 7:42
Daniel W.Daniel W.
226212
226212
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can create an image from an Azure VM. For example, you can create a windows image from the windows VM through PowerShell, see Create and use a custom image for virtual machine scale sets with Azure PowerShell. When the image is OK, Just create the VMSS like this:
New-AzureRmVmss `
-ResourceGroupName "myResourceGroup" `
-Location "EastUS" `
-VMScaleSetName "myScaleSet" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-PublicIpAddressName "myPublicIPAddress" `
-LoadBalancerName "myLoadBalancer" `
-UpgradePolicyMode "Automatic" `
-ImageName "yourImage"
Also, the snapshot is OK, but you should create the image from the snapshot first. And then create the VMSS from the image. With the command New-AzureRmImage
, the image should be a managed image, so you cannot see the URI. Just use the managed image Id in the command like this:
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
And just talk about how to create images, I would suggest you the Packer and there is an example here.
Update
I assume that your custom image is prepared. And the PowerShell script like this:
#Get the custom image
$image = Get-AzureRmImage -ResourceGroupName charlesTerraform -ImageName myPackerImage
# Get the existing Vnet
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName charlesTerraform -Name pakcerVnet
#IP configuration
$ipName = "ipConfig"
#create the IP configuration
$ipConfig = New-AzureRmVmssIpConfig -Name $ipName -LoadBalancerBackendAddressPoolsId $null -SubnetId $vnet.Subnets[0].Id
#create vmss configuration
$vmss = New-AzureRmVmssConfig -Location "East US" -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
##Add the network interface configuration to the scale set configuration
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
# set the stroage profile
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId $image.Id -OsDiskOsType Linux
#set the os profile
Set-AzureRmVmssOSProfile -ComputerNamePrefix "Test" -AdminUsername "azureuser" -AdminPassword "azureuser@2018" -VirtualMachineScaleSet $vmss
#create the vmss
New-AzureRmVmss -ResourceGroupName charlesTerraform -Name TestVmss -VirtualMachineScaleSet $vmss
Use a Image direkt from AzureVm is not a real option for me. First create Disk does not work, see edit in the post.
– Daniel W.
Nov 26 '18 at 8:32
The disk I said in the answer means a managed image. It's impossible if you want to create VMSS from a snapshot directly. You must create an image from a snapshot through the commandNew-AzureRmImage
. Then use the commandNew-AzureRmVmss
with the parameterImageName
to use the image. You could take a look at the link about custom image.
– Charles Xu
Nov 26 '18 at 8:41
Ok sad but like my sample code shows, I try create the image from the snapshot. But I can not use New-AzureRmVmss with ImageName because I need to go by use of New-AzureRmVmssConfig because I need to use a existing Network. And in the Parameter Set I can not use ImageName if I set VirtualMachineScaleSet parameter. So I have to use Set-AzureRmVmssStorageProfile.
– Daniel W.
Nov 26 '18 at 9:40
Maybe you can try the commandSet-AzureRmVmssStorageProfile
with the parameter-ImageReferenceId
, without other image parameters.
– Charles Xu
Nov 26 '18 at 9:45
For example,Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
.
– Charles Xu
Nov 26 '18 at 9:49
|
show 10 more comments
folks. So what about create a "Virtual Machine in Scale Set" from a customized snapshot. Is this possible or one scale set could only have one base image and all vms under this scale set could only reimaged to the same baseline ?
I only know the workaround with first creating an image from the snapshot, I would also find it nice to have a direct way.
– Daniel W.
Dec 18 '18 at 7:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476596%2fhow-to-create-a-vm-scale-set-from-a-snapshot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create an image from an Azure VM. For example, you can create a windows image from the windows VM through PowerShell, see Create and use a custom image for virtual machine scale sets with Azure PowerShell. When the image is OK, Just create the VMSS like this:
New-AzureRmVmss `
-ResourceGroupName "myResourceGroup" `
-Location "EastUS" `
-VMScaleSetName "myScaleSet" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-PublicIpAddressName "myPublicIPAddress" `
-LoadBalancerName "myLoadBalancer" `
-UpgradePolicyMode "Automatic" `
-ImageName "yourImage"
Also, the snapshot is OK, but you should create the image from the snapshot first. And then create the VMSS from the image. With the command New-AzureRmImage
, the image should be a managed image, so you cannot see the URI. Just use the managed image Id in the command like this:
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
And just talk about how to create images, I would suggest you the Packer and there is an example here.
Update
I assume that your custom image is prepared. And the PowerShell script like this:
#Get the custom image
$image = Get-AzureRmImage -ResourceGroupName charlesTerraform -ImageName myPackerImage
# Get the existing Vnet
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName charlesTerraform -Name pakcerVnet
#IP configuration
$ipName = "ipConfig"
#create the IP configuration
$ipConfig = New-AzureRmVmssIpConfig -Name $ipName -LoadBalancerBackendAddressPoolsId $null -SubnetId $vnet.Subnets[0].Id
#create vmss configuration
$vmss = New-AzureRmVmssConfig -Location "East US" -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
##Add the network interface configuration to the scale set configuration
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
# set the stroage profile
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId $image.Id -OsDiskOsType Linux
#set the os profile
Set-AzureRmVmssOSProfile -ComputerNamePrefix "Test" -AdminUsername "azureuser" -AdminPassword "azureuser@2018" -VirtualMachineScaleSet $vmss
#create the vmss
New-AzureRmVmss -ResourceGroupName charlesTerraform -Name TestVmss -VirtualMachineScaleSet $vmss
Use a Image direkt from AzureVm is not a real option for me. First create Disk does not work, see edit in the post.
– Daniel W.
Nov 26 '18 at 8:32
The disk I said in the answer means a managed image. It's impossible if you want to create VMSS from a snapshot directly. You must create an image from a snapshot through the commandNew-AzureRmImage
. Then use the commandNew-AzureRmVmss
with the parameterImageName
to use the image. You could take a look at the link about custom image.
– Charles Xu
Nov 26 '18 at 8:41
Ok sad but like my sample code shows, I try create the image from the snapshot. But I can not use New-AzureRmVmss with ImageName because I need to go by use of New-AzureRmVmssConfig because I need to use a existing Network. And in the Parameter Set I can not use ImageName if I set VirtualMachineScaleSet parameter. So I have to use Set-AzureRmVmssStorageProfile.
– Daniel W.
Nov 26 '18 at 9:40
Maybe you can try the commandSet-AzureRmVmssStorageProfile
with the parameter-ImageReferenceId
, without other image parameters.
– Charles Xu
Nov 26 '18 at 9:45
For example,Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
.
– Charles Xu
Nov 26 '18 at 9:49
|
show 10 more comments
You can create an image from an Azure VM. For example, you can create a windows image from the windows VM through PowerShell, see Create and use a custom image for virtual machine scale sets with Azure PowerShell. When the image is OK, Just create the VMSS like this:
New-AzureRmVmss `
-ResourceGroupName "myResourceGroup" `
-Location "EastUS" `
-VMScaleSetName "myScaleSet" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-PublicIpAddressName "myPublicIPAddress" `
-LoadBalancerName "myLoadBalancer" `
-UpgradePolicyMode "Automatic" `
-ImageName "yourImage"
Also, the snapshot is OK, but you should create the image from the snapshot first. And then create the VMSS from the image. With the command New-AzureRmImage
, the image should be a managed image, so you cannot see the URI. Just use the managed image Id in the command like this:
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
And just talk about how to create images, I would suggest you the Packer and there is an example here.
Update
I assume that your custom image is prepared. And the PowerShell script like this:
#Get the custom image
$image = Get-AzureRmImage -ResourceGroupName charlesTerraform -ImageName myPackerImage
# Get the existing Vnet
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName charlesTerraform -Name pakcerVnet
#IP configuration
$ipName = "ipConfig"
#create the IP configuration
$ipConfig = New-AzureRmVmssIpConfig -Name $ipName -LoadBalancerBackendAddressPoolsId $null -SubnetId $vnet.Subnets[0].Id
#create vmss configuration
$vmss = New-AzureRmVmssConfig -Location "East US" -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
##Add the network interface configuration to the scale set configuration
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
# set the stroage profile
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId $image.Id -OsDiskOsType Linux
#set the os profile
Set-AzureRmVmssOSProfile -ComputerNamePrefix "Test" -AdminUsername "azureuser" -AdminPassword "azureuser@2018" -VirtualMachineScaleSet $vmss
#create the vmss
New-AzureRmVmss -ResourceGroupName charlesTerraform -Name TestVmss -VirtualMachineScaleSet $vmss
Use a Image direkt from AzureVm is not a real option for me. First create Disk does not work, see edit in the post.
– Daniel W.
Nov 26 '18 at 8:32
The disk I said in the answer means a managed image. It's impossible if you want to create VMSS from a snapshot directly. You must create an image from a snapshot through the commandNew-AzureRmImage
. Then use the commandNew-AzureRmVmss
with the parameterImageName
to use the image. You could take a look at the link about custom image.
– Charles Xu
Nov 26 '18 at 8:41
Ok sad but like my sample code shows, I try create the image from the snapshot. But I can not use New-AzureRmVmss with ImageName because I need to go by use of New-AzureRmVmssConfig because I need to use a existing Network. And in the Parameter Set I can not use ImageName if I set VirtualMachineScaleSet parameter. So I have to use Set-AzureRmVmssStorageProfile.
– Daniel W.
Nov 26 '18 at 9:40
Maybe you can try the commandSet-AzureRmVmssStorageProfile
with the parameter-ImageReferenceId
, without other image parameters.
– Charles Xu
Nov 26 '18 at 9:45
For example,Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
.
– Charles Xu
Nov 26 '18 at 9:49
|
show 10 more comments
You can create an image from an Azure VM. For example, you can create a windows image from the windows VM through PowerShell, see Create and use a custom image for virtual machine scale sets with Azure PowerShell. When the image is OK, Just create the VMSS like this:
New-AzureRmVmss `
-ResourceGroupName "myResourceGroup" `
-Location "EastUS" `
-VMScaleSetName "myScaleSet" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-PublicIpAddressName "myPublicIPAddress" `
-LoadBalancerName "myLoadBalancer" `
-UpgradePolicyMode "Automatic" `
-ImageName "yourImage"
Also, the snapshot is OK, but you should create the image from the snapshot first. And then create the VMSS from the image. With the command New-AzureRmImage
, the image should be a managed image, so you cannot see the URI. Just use the managed image Id in the command like this:
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
And just talk about how to create images, I would suggest you the Packer and there is an example here.
Update
I assume that your custom image is prepared. And the PowerShell script like this:
#Get the custom image
$image = Get-AzureRmImage -ResourceGroupName charlesTerraform -ImageName myPackerImage
# Get the existing Vnet
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName charlesTerraform -Name pakcerVnet
#IP configuration
$ipName = "ipConfig"
#create the IP configuration
$ipConfig = New-AzureRmVmssIpConfig -Name $ipName -LoadBalancerBackendAddressPoolsId $null -SubnetId $vnet.Subnets[0].Id
#create vmss configuration
$vmss = New-AzureRmVmssConfig -Location "East US" -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
##Add the network interface configuration to the scale set configuration
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
# set the stroage profile
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId $image.Id -OsDiskOsType Linux
#set the os profile
Set-AzureRmVmssOSProfile -ComputerNamePrefix "Test" -AdminUsername "azureuser" -AdminPassword "azureuser@2018" -VirtualMachineScaleSet $vmss
#create the vmss
New-AzureRmVmss -ResourceGroupName charlesTerraform -Name TestVmss -VirtualMachineScaleSet $vmss
You can create an image from an Azure VM. For example, you can create a windows image from the windows VM through PowerShell, see Create and use a custom image for virtual machine scale sets with Azure PowerShell. When the image is OK, Just create the VMSS like this:
New-AzureRmVmss `
-ResourceGroupName "myResourceGroup" `
-Location "EastUS" `
-VMScaleSetName "myScaleSet" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-PublicIpAddressName "myPublicIPAddress" `
-LoadBalancerName "myLoadBalancer" `
-UpgradePolicyMode "Automatic" `
-ImageName "yourImage"
Also, the snapshot is OK, but you should create the image from the snapshot first. And then create the VMSS from the image. With the command New-AzureRmImage
, the image should be a managed image, so you cannot see the URI. Just use the managed image Id in the command like this:
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
And just talk about how to create images, I would suggest you the Packer and there is an example here.
Update
I assume that your custom image is prepared. And the PowerShell script like this:
#Get the custom image
$image = Get-AzureRmImage -ResourceGroupName charlesTerraform -ImageName myPackerImage
# Get the existing Vnet
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName charlesTerraform -Name pakcerVnet
#IP configuration
$ipName = "ipConfig"
#create the IP configuration
$ipConfig = New-AzureRmVmssIpConfig -Name $ipName -LoadBalancerBackendAddressPoolsId $null -SubnetId $vnet.Subnets[0].Id
#create vmss configuration
$vmss = New-AzureRmVmssConfig -Location "East US" -SkuCapacity 2 -SkuName "Standard_DS1_v2" -UpgradePolicyMode "manual" -ErrorAction Stop
##Add the network interface configuration to the scale set configuration
Add-AzureRmVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmss -Name "vmssNetwork" -Primary $true -IPConfiguration $ipConfig
# set the stroage profile
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId $image.Id -OsDiskOsType Linux
#set the os profile
Set-AzureRmVmssOSProfile -ComputerNamePrefix "Test" -AdminUsername "azureuser" -AdminPassword "azureuser@2018" -VirtualMachineScaleSet $vmss
#create the vmss
New-AzureRmVmss -ResourceGroupName charlesTerraform -Name TestVmss -VirtualMachineScaleSet $vmss
edited Nov 28 '18 at 8:50
answered Nov 26 '18 at 7:52
Charles XuCharles Xu
4,8261211
4,8261211
Use a Image direkt from AzureVm is not a real option for me. First create Disk does not work, see edit in the post.
– Daniel W.
Nov 26 '18 at 8:32
The disk I said in the answer means a managed image. It's impossible if you want to create VMSS from a snapshot directly. You must create an image from a snapshot through the commandNew-AzureRmImage
. Then use the commandNew-AzureRmVmss
with the parameterImageName
to use the image. You could take a look at the link about custom image.
– Charles Xu
Nov 26 '18 at 8:41
Ok sad but like my sample code shows, I try create the image from the snapshot. But I can not use New-AzureRmVmss with ImageName because I need to go by use of New-AzureRmVmssConfig because I need to use a existing Network. And in the Parameter Set I can not use ImageName if I set VirtualMachineScaleSet parameter. So I have to use Set-AzureRmVmssStorageProfile.
– Daniel W.
Nov 26 '18 at 9:40
Maybe you can try the commandSet-AzureRmVmssStorageProfile
with the parameter-ImageReferenceId
, without other image parameters.
– Charles Xu
Nov 26 '18 at 9:45
For example,Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
.
– Charles Xu
Nov 26 '18 at 9:49
|
show 10 more comments
Use a Image direkt from AzureVm is not a real option for me. First create Disk does not work, see edit in the post.
– Daniel W.
Nov 26 '18 at 8:32
The disk I said in the answer means a managed image. It's impossible if you want to create VMSS from a snapshot directly. You must create an image from a snapshot through the commandNew-AzureRmImage
. Then use the commandNew-AzureRmVmss
with the parameterImageName
to use the image. You could take a look at the link about custom image.
– Charles Xu
Nov 26 '18 at 8:41
Ok sad but like my sample code shows, I try create the image from the snapshot. But I can not use New-AzureRmVmss with ImageName because I need to go by use of New-AzureRmVmssConfig because I need to use a existing Network. And in the Parameter Set I can not use ImageName if I set VirtualMachineScaleSet parameter. So I have to use Set-AzureRmVmssStorageProfile.
– Daniel W.
Nov 26 '18 at 9:40
Maybe you can try the commandSet-AzureRmVmssStorageProfile
with the parameter-ImageReferenceId
, without other image parameters.
– Charles Xu
Nov 26 '18 at 9:45
For example,Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
.
– Charles Xu
Nov 26 '18 at 9:49
Use a Image direkt from AzureVm is not a real option for me. First create Disk does not work, see edit in the post.
– Daniel W.
Nov 26 '18 at 8:32
Use a Image direkt from AzureVm is not a real option for me. First create Disk does not work, see edit in the post.
– Daniel W.
Nov 26 '18 at 8:32
The disk I said in the answer means a managed image. It's impossible if you want to create VMSS from a snapshot directly. You must create an image from a snapshot through the command
New-AzureRmImage
. Then use the command New-AzureRmVmss
with the parameter ImageName
to use the image. You could take a look at the link about custom image.– Charles Xu
Nov 26 '18 at 8:41
The disk I said in the answer means a managed image. It's impossible if you want to create VMSS from a snapshot directly. You must create an image from a snapshot through the command
New-AzureRmImage
. Then use the command New-AzureRmVmss
with the parameter ImageName
to use the image. You could take a look at the link about custom image.– Charles Xu
Nov 26 '18 at 8:41
Ok sad but like my sample code shows, I try create the image from the snapshot. But I can not use New-AzureRmVmss with ImageName because I need to go by use of New-AzureRmVmssConfig because I need to use a existing Network. And in the Parameter Set I can not use ImageName if I set VirtualMachineScaleSet parameter. So I have to use Set-AzureRmVmssStorageProfile.
– Daniel W.
Nov 26 '18 at 9:40
Ok sad but like my sample code shows, I try create the image from the snapshot. But I can not use New-AzureRmVmss with ImageName because I need to go by use of New-AzureRmVmssConfig because I need to use a existing Network. And in the Parameter Set I can not use ImageName if I set VirtualMachineScaleSet parameter. So I have to use Set-AzureRmVmssStorageProfile.
– Daniel W.
Nov 26 '18 at 9:40
Maybe you can try the command
Set-AzureRmVmssStorageProfile
with the parameter -ImageReferenceId
, without other image parameters.– Charles Xu
Nov 26 '18 at 9:45
Maybe you can try the command
Set-AzureRmVmssStorageProfile
with the parameter -ImageReferenceId
, without other image parameters.– Charles Xu
Nov 26 '18 at 9:45
For example,
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
.– Charles Xu
Nov 26 '18 at 9:49
For example,
Set-AzureRmVmssStorageProfile -VirtualMachineScaleSet $vmss -OsDiskCreateOption "FromImage" -OsDiskCaching "None" -ImageReferenceId yourImageId -OsDiskOsType Windows -OsDiskName "C"
.– Charles Xu
Nov 26 '18 at 9:49
|
show 10 more comments
folks. So what about create a "Virtual Machine in Scale Set" from a customized snapshot. Is this possible or one scale set could only have one base image and all vms under this scale set could only reimaged to the same baseline ?
I only know the workaround with first creating an image from the snapshot, I would also find it nice to have a direct way.
– Daniel W.
Dec 18 '18 at 7:48
add a comment |
folks. So what about create a "Virtual Machine in Scale Set" from a customized snapshot. Is this possible or one scale set could only have one base image and all vms under this scale set could only reimaged to the same baseline ?
I only know the workaround with first creating an image from the snapshot, I would also find it nice to have a direct way.
– Daniel W.
Dec 18 '18 at 7:48
add a comment |
folks. So what about create a "Virtual Machine in Scale Set" from a customized snapshot. Is this possible or one scale set could only have one base image and all vms under this scale set could only reimaged to the same baseline ?
folks. So what about create a "Virtual Machine in Scale Set" from a customized snapshot. Is this possible or one scale set could only have one base image and all vms under this scale set could only reimaged to the same baseline ?
answered Dec 8 '18 at 6:42
dave zhoudave zhou
1925
1925
I only know the workaround with first creating an image from the snapshot, I would also find it nice to have a direct way.
– Daniel W.
Dec 18 '18 at 7:48
add a comment |
I only know the workaround with first creating an image from the snapshot, I would also find it nice to have a direct way.
– Daniel W.
Dec 18 '18 at 7:48
I only know the workaround with first creating an image from the snapshot, I would also find it nice to have a direct way.
– Daniel W.
Dec 18 '18 at 7:48
I only know the workaround with first creating an image from the snapshot, I would also find it nice to have a direct way.
– Daniel W.
Dec 18 '18 at 7:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476596%2fhow-to-create-a-vm-scale-set-from-a-snapshot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown