How to Reserve Ip When Provisioning Azure Vm (Resource Manager)

How to reserve IP when provisioning Azure VM (resource manager)

You need to define a public IP address as part of your Resource Groupm then assign it to the correct Virtual NIC (Network Interface Card).

A public IP Address resource type represents a DNS name on the public internet. It may be used to provide a DNS name to either a virtual IP address (VIP) hosted on an Azure Load Balancer or a public instance IP address (PIP) hosted directly on a VM.

With the Azure CLI, you need to write something like this:

azure network public-ip create -g MyResourceGroup -a Dynamic -l northeurope MyPublicIP

Then you would assign your IP to the Virtual NIC of the VM. Both the VM and the NIC are part of the same resource group:

azure network nic set -g MyResourceGroup -p MyPublicIP MyNicName

You can use "azure network nic list" to get the name of the NIC.

It also seems that currently only Dynamic Public IPs are supported for being used directly on VMs (in ARM mode). Right now, static IPs can only be assigned to Load Balancer configurations. Trying to use "-a Static" spits out an error when doing "azure network nic set":

Network interface
xxx
references public IP address
yyy
with AllocationMethod property set to Static. Currently this
configuration is not supported. Network interfaces can use only
dynamic public IPs.

I would also like to find out when this will be supported.

edit: here is a good Azure CLI reference. You can also use -h to get command usage help.

Reserved IP's for Azure Resource Manager based Virtual machines

A reserved IP address is for Classic Deploy Model only, and this part of functionality is integrated into the public IP address. A static public IP address acts exactly like a reserved IP address. No need and not possible to assign a classic reserved IP address to an ARM deployed VM. Assigning a static public IP to a load balancer is exactly the same as assigning one to a NIC.

Microsoft does have ARM REST API for classic reserved IP address, but I can't find any documents. So, I can only describe it here a little bit.

Get a reserved IP address.

GET https://management.azure.com/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.ClassicNetwork/ReservedIps/<reserved IP address name>?api-version=2015-12-01

Headers: Authorization, the same as other ARM REST API.

Response body:

{
"properties": {
"ipAddress": "<ip address>",
"status": "Created",
"provisioningState": "Succeeded",
"inUse": false
},
"id": "/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.ClassicNetwork/ReservedIps/<reserved ip address name>",
"name": "<reserved ip address name>",
"type": "Microsoft.ClassicNetwork/ReservedIps",
"location": "eastasia"
}



Create a reserved IP address.

PUT https://management.azure.com/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.ClassicNetwork/ReservedIps/<reserved IP address name>?api-version=2015-12-01

Headers: Authorization, the same as other ARM REST API. Content-Type, "application/json"

Request body:

{
"properties": {
},
"id": "/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.ClassicNetwork/ReservedIps/<reserved ip address name>",
"name": "<reserved ip address name>",
"type": "Microsoft.ClassicNetwork/ReservedIps",
"location": "eastasia"
}



Delete a reserved IP address.

DELETE https://management.azure.com/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.ClassicNetwork/ReservedIps/<reserved IP address name>?api-version=2015-12-01

Headers: Authorization, the same as other ARM REST API.



The Rest API does not support POST or PATCH.

For VM with Load Balancer, I have written a sample template.

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string",
"defaultValue": "loadbalancertest2",
"metadata": {
"description": "The Storage Name of you VM OSDisk and DataDisk"
}
},
"apiVersion": {
"type": "string",
"defaultValue": "2016-03-30",
"metadata": {
"description": "The API Version"
}
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"metadata": {
"description": "The Storage Account Type"
}
},
"publicIPAddressName": {
"type": "string",
"defaultValue": "loadbalancertest",
"metadata": {
"description": "The public IP Address Name"
}
},
"publicIPAddressType": {
"type": "string",
"defaultValue": "Static",
"metadata": {
"description": "The public IP Address Type"
}
},
"dnsNameforLBIP": {
"type": "string",
"defaultValue": "loadbalancertest",
"metadata": {
"description": "a unique DNS Name for LBIP"
}
},
"virtualNetworkName": {
"type": "string",
"defaultValue": "loadbalancertest",
"metadata": {
"description": "The Virtual Network Name"
}
},
"nicName": {
"type": "string",
"defaultValue": "loadbalancertest",
"metadata": {
"description": "The Network Interface Card Name"
}
},
"loadBalancerName": {
"type": "string",
"defaultValue": "loadbalancertest",
"metadata": {
"description": "The Load Balancer Name"
}
},
"vmName": {
"type": "string",
"defaultValue": "lbtest",
"metadata": {
"description": "The Virtual Machine Name"
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "The admin Username"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "The admin Password"
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D1",
"metadata": {
"description": "The Virtual Machine Size"
}
}
},
"variables": {
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',parameters('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/default')]",
"publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',parameters('publicIPAddressName'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[parameters('storageAccountName')]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
}
},
{
"apiVersion": "[parameters('apiVersion')]",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[parameters('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "[parameters('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsNameforLBIP')]"
}
}
},
{
"apiVersion": "[parameters('apiVersion')]",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"subnets": [
{
"name": "default",
"properties": {
"addressPrefix": "10.0.0.0/24"
}
}
]
}
},
{
"apiVersion": "[parameters('apiVersion')]",
"type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('nicName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"[concat('Microsoft.Network/loadBalancers/', parameters('loadBalancerName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
}
},
"loadBalancerBackendAddressPools": [
{
"id": "[concat('Microsoft.Network/loadBalancers/', parameters('loadBalancerName'), '/backendAddressPools/loadBalancerBackEnd')]"
}
]
}
]
}
},
{
"apiVersion": "[parameters('apiVersion')]",
"name": "[parameters('loadBalancerName')]",
"type": "Microsoft.Network/loadBalancers",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPAddressName'))]"
],
"properties": {
"frontendIPConfigurations": [
{
"name": "loadBalancerFrontEnd",
"properties": {
"publicIPAddress": {
"id": "[variables('publicIPAddressID')]"
}
}
}
],
"backendAddressPools": [
{
"name": "loadBalancerBackEnd"
}
],
"loadBalancingRules": [
],
"probes": [
]
}
},
{
"apiVersion": "[parameters('apiVersion')]",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2012-R2-Datacenter",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/vhds/loadbalancertestOS.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
},
"dataDisks": [
{
"name": "datadisk1",
"diskSizeGB": "100",
"lun": 0,
"vhd": {
"uri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net/vhds/loadbalancertestData.vhd')]"
},
"createOption": "Empty"
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',parameters('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": "true",
"storageUri": "[concat('http://',parameters('storageAccountName'),'.blob.core.windows.net')]"
}
}
}
}
]
}

A Load Balancer is something set between NICs and public IP addresses, load balancing the internet traffic. For more details, see Azure Load Balancer overview

Update

About converting a classic reserved IP address into a static public IP address, here is what I have found. If you follow the article "Migrate IaaS resources from classic to Azure Resource Manager by using Azure PowerShell", assign the reserved IP to a Cloud Service with a Virtual Machine, and migrate the ASM virtual machine into an ARM virtual machine, the reserved IP will be converted into a static public IP. I have tested a virtual machine with a virtual network. It does work.

Set Azure Reserved IP on cloud service via powershell

In my test, I reproduce your error, I just create a cloud service via new portal, and then associate a reserved IP address to it, the error occur.

PS C:\Users> Set-AzureReservedIPAssociation -ReservedIPName my9 -ServiceName "jasontest323"
Set-AzureReservedIPAssociation : ResourceNotFound: No deployments were found.
At line:1 char:1
+ Set-AzureReservedIPAssociation -ReservedIPName my9 -ServiceName "jaso ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureReservedIPAssociation], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.SetAzureReservedIPAssociationCmdlet

After that, I create another cloud service and a VM, then assiscate a reserved IP address to this cloud service, it works.

PS C:\Users> Set-AzureReservedIPAssociation -ReservedIPName my9 -ServiceName "jasonvm3659"

OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
Set-AzureReservedIPAssociation 05ccff35-5642-7cc6-9c6b-b5dfe2d1603d Succeeded

So, I check the status of the two cloud service, I find when the Production is running, the command will work.
Sample Image

Sample Image

We can use PowerShell to check the deployment:

PS C:\Users> Get-AzureDeployment -ServiceName jasontest323
Get-AzureDeployment : ResourceNotFound: No deployments were found.
OperationID : '27da300bc3c67a5bbdbc954c1c19e3e7'
At line:1 char:1
+ Get-AzureDeployment -ServiceName jasontest323
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureDeployment], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.HostedServices.GetAzureDeploymentCommand

PS C:\Users> Get-AzureDeployment -ServiceName jasonvm3659

SdkVersion :
RollbackAllowed : False
Slot : Production
Name : jasonvm3659
DeploymentName : jasonvm3659
Url : http://jasonvm3659.cloudapp.net/
Status : Running
CurrentUpgradeDomain : 0
CurrentUpgradeDomainState :
UpgradeType :
RoleInstanceList : {jasonvm}
Configuration : <ServiceConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="jasonvm">
<Instances count="1" />
</Role>
</ServiceConfiguration>
DeploymentId : fc627acb502a4a979b08c42f69cccf72
Label : jasonvm3659
VNetName : Group jasontest321 jasontest321
DnsSettings :
OSVersion :
RolesConfiguration : {[jasonvm, Microsoft.WindowsAzure.Commands.ServiceManagement.Model.RoleConfiguration]}
VirtualIPs : {jasonvm3659ContractContract}
ReservedIPName : my9
CreatedTime : 3/29/2017 1:10:28 PM
LastModifiedTime : 3/29/2017 1:27:42 PM
Locked : False
InternalLoadBalancerName :
LoadBalancers : {}
ExtensionConfiguration :
ServiceName : jasonvm3659
OperationDescription : Get-AzureDeployment
OperationId : f8b8xxxx-xxxx-xxxx-xxxx-xxxx2cdc1daa
OperationStatus : Succeeded

The reserved IPs work for classic module, only be used for VMs and cloud service instance roles exposed through a VIP.

So we should check the deployment with powershell Get-AzureDeployment -ServiceName primosguardo365 first.

Refresh IP address for Azure VM via REST API

As your mentioned: In the web interface, stopping and starting the VM usually causes the public IP to change.

Generally, the stop operation in the web UI actually does deallocate operation, so you need to use REST API Deallocate and Start to trigger the public IP address changed.

Virtual Machines - Deallocate

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate?api-version=2020-12-01

Virtual Machines - Start

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start?api-version=2020-12-01

How to create a Virtual Machine in Microsoft Azure without PUBLIC VIRTUAL IP (VIP) address?

This is incorrect as of 11/29/2016 You can now choose in the provisioning stage through Azure portal to set the public IP Address as NONE. This will allow only communication within the virtual network that the VM is living in.

Change IP addresses of a Azure network interface

To change the Azure network interface IP addresses, one important thing is that a network interface must always have at least one private IPv4 address assigned to it. So the right sequence is:

  1. Create a new IP config with the new IP address;
  2. Remove the old IP config as you expect.

You can use the REST API: Network Interfaces - Create Or Update to achieve it, and here is an example, I assume your network interface has only one IP config named ipconfig1, then use the REST API with the body below:

{
"name": "nicName",
"id": "nicResourceId",
"location": "region",
"properties": {
"provisioningState": "Succeeded",
"ipConfigurations": [
{
"name": "ipconfig2",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "subnetResourceId"
},
"primary": true,
"privateIPAddressVersion": "IPv4"
}
}
],
"dnsSettings": {
"dnsServers": [],
"appliedDnsServers": []
},
"enableAcceleratedNetworking": true,
"enableIPForwarding": false
},
"type": "Microsoft.Network/networkInterfaces"
}

When it finishes, your network interface will have only one IP config named ipconfig2 with a new IP address. You can also use the static allocation method and use a special IP address as you want.

Linux VM stuck in Provisioning for last 2hrs

I'm quite sure this is the same question as in ServerFault but I posted here too just in case someone looking ^_^

I have tried the guide and it works for me (I created new Centos VM
and capture it). I tried login to the new VM from the image and I
still have my sudo access. So, the guide is correct maybe you just do
something wrong in the process. And also make sure you use the new
user that you created for the new VM not the old one from the VM that
you deprovision.

For the second question, if you deprovision VM and capture it, the VM
will be removed so you cannot access it again



Related Topics



Leave a reply



Submit