Reserve external IP on Azure Cloud Service

When we create a VM on Azure, at the same time we create a Cloud Service. Later we can create more VMs on the same cloud service. Each cloud service has a unique Public IP. For as long the Cloud Service has at least one VS running this Public IP remains the same. If all VMs of a Cloud Service are off then the Public IP is released and next time the VM is powered on it will take a new Public IP.

Using PowerShell we can reserve a Public IP for as long as the Cloud Service exists, with or without VMs.

First we need to create a Virtual Network from the portal. Go to “Networks” and create a new Virtual Network. We can use the “Quick Create”.

Second we need the Azure PowerShell installed, it can be found here: http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/ and we connect using the username/password method, the command is Add-AzureAccount

#Create the Public IP Reservation:
$reservedIP = "reserved ip name"
$location = "West Europe"
New-AzureReservedIP -ReservedIPName $reservedIP -Location $location

#Collect the configuration settings for the new VM:
$serviceName = "azure service name for VM"
$adminUser = "VM admin user name"
$password = "VM admin password"
$location = "West Europe"
$reservedIP = "reserved ip name"
$vmName = "VM name"

#Choose the size of the VM. Use this list: https://msdn.microsoft.com/en-us/library/dn168976%28v=nav.70%29.aspx#
$vmSize = "Medium"

#Provide the Operating System. Use this post to get a list of the available images: https://msdn.microsoft.com/en-us/library/azure/jj157191.aspx?f=255&MSPPError=-2147217396
$imageFamily = "Windows Server 2012 R2 Datacenter"
$imageName = Get-AzureVMImage | where { $_.ImageFamily -eq $imageFamily } | sort PublishedDate -Descending | select -ExpandProperty ImageName -First 1

#Add the configuration settings for the new VM to a variable:
$vm1 = New-AzureVMConfig -Name $vmName -InstanceSize $vmSize -imagename $imagename | Add-AzureProvisioningConfig -Windows -AdminUsername $adminUser -Password $password | set-azuresubnet subnet-1

#Create the VM and the Cloud Service with the Reserved Public IP
New-AzureVM -Location $location -VMs $vm1 -vnetname testnet2 -servicename $servicename -reservedipname $reservedipname Δίνουμε την εντολή για να ξεκινήσει η δημιουργία.

 

 

Share

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.