Over a million developers have joined DZone.

Moving a Microsoft Azure VM to a Different Subnet Within a Virtual Network

DZone's Guide to

Moving a Microsoft Azure VM to a Different Subnet Within a Virtual Network

· Cloud Zone ·
Free Resource

Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.

In Microsoft Azure, an administrator can now use PowerShell to migrate a VM from one subnet to another within the same virtual network. This offers an opportunity to reorganize an application topology for better managing subnet capacity and grouping. For instance, when an existing subnet, ABC, is running out of IP addresses, customers can move  the associated VMs to a different and perhaps larger subnet. At this time, subnet ABC can then be deleted to recover the IP address space.

The logical process to carry out a subnet migration is to:

  1. Migrate a VM from one subnet to another, followed by
  2. Update the VM configuration which will restart the VM

The MSDN documentation at http://msdn.microsoft.com/en-us/library/azure/dn643636.aspx offers a sample PowerShell statement as below.

Get-AzureVM –Name <a target VM name> –ServiceName <the associated service name> `
| Set-AzureSubnet –SubnetNames <a target subnet to migrate to> `
| Update-AzureVM

And I am here providing a sample scenario of moving a VM from a DEV subnet to a TEST one as illustrated below.


A virtual network, fooNet, has three subnets: AD, DEV, and TEST, while each subnet is configured with a specific IP address range as shown.

image The intent is to move the VM, app1, currently in DEV to the subnet, TEST.
image The VM, app1, is deployed to the service, foo-devtest, i.e. http://foo-devtest.cloudapp.net.
image An ISE session is connecting to the Microsoft Azure subscription account and has successfully moved the VM to the target subnet, TEST.

For those who are not familiar with Microsoft Azure PowerShell, a self-training tool called Quick Start Kit (QSK) is available at http://yungchou.wordpress.com/2014/01/21/announcing-windows-azure-iaas-quick-start-kit-qsk-at-http-aka-ms-qsk/.
image The VM now resides in the subnet, TEST.

Join us in exploring application and infrastructure changes required for running scalable, observable, and portable apps on Kubernetes.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}