问题
The Question is twofold. Firstly, What is the way to assign a reserved IP address as a public IP to a resource manager based virtual machine. Does it only involve setting IP allocation method to static in template file (then assigning that to NIC hence the VM of course) or there is some other way to do this, i have read over the internet about load balancers but i am not getting how to use them using a template file, please refer any links. Secondly, does any rest api or .net sdk exist to deal with reserved IPs in Azure Resource Management model (e.g. Create, associate, disassociate methods). I have found the api for Azure service management model (https://msdn.microsoft.com/library/azure/dn722420.aspx) but i am not finding the same for Azure resource management model. Thanks
回答1:
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.
来源:https://stackoverflow.com/questions/36622975/reserved-ips-for-azure-resource-manager-based-virtual-machines