[英]Is it possible to update an existing azure load balancer with new lb rules or health probe using arm template
I tried with the above code but not able to get it right.我尝试使用上面的代码,但无法正确使用。 And also, I can see that it is asking for the old rules.
而且,我可以看到它要求旧规则。 I am trying to update the new rules while not disturbing the old rules.
我试图在不打扰旧规则的情况下更新新规则。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"lbName": {
"type": "string"
},
"lbLocation": {
"type": "string"
},
"vnetId": {
"type": "string"
},
"subnetId": {
"type": "string"
},
"healthProbes": {
"type": "array",
"defaultValue": [
{
"name": "HealthProbe-TCP-80",
"protocol": "TCP",
"port": "80",
"intervalInSeconds": "15",
"numberOfProbes": "2",
"requestPath": null
},
{
"name": "HealthProbe-TCP-443",
"protocol": "TCP",
"port": "443",
"intervalInSeconds": "15",
"numberOfProbes": "2",
"requestPath": null
},
{
"name": "HealthProbe-HTTP-443",
"protocol": "HTTP",
"port": "443",
"intervalInSeconds": "15",
"numberOfProbes": "2",
"requestPath": "TestPath"
}
]
}
},
"variables": {
"virtualNetworkName": "[parameters('vnetId')]",
"subnetName": "[Parameters('subnetId')]",
"frontEndIPConfigName": "LoadBalancerFrontEnd",
"feId": "[concat(parameters('lbName'),'/frontendIPConfigurations/loadBalancerFrontend')]",
"backendPoolConfigName": "qwertyBEPool",
"beId": "[concat(parameters('lbName'), '/backendAddressPools/qwertyBEPool')]",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
},
"resources": [
{
"apiVersion": "2019-06-01",
"name": "[parameters('lbName')]",
"type": "Microsoft.Network/loadBalancers",
"location": "[parameters('lbLocation')]",
"properties": {
"frontendIPConfigurations": [
{
"name": "LoadBalancerFrontEnd",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
],
"backendAddressPools": [
{
"name": "LoadBalancerBackend"
}
],
"copy": [
{
"name": "probes",
"count": "[length(parameters('healthProbes'))]",
"input": {
"name": "[parameters('healthProbes')[copyIndex('probes')].name]",
"properties": {
"protocol": "[parameters('healthProbes')[copyIndex('probes')].protocol]",
"port": "[parameters('healthProbes')[copyIndex('probes')].port]",
"intervalInSeconds": "[parameters('healthProbes')[copyIndex('probes')].intervalInSeconds]",
"numberOfProbes": "[parameters('healthProbes')[copyIndex('probes')].numberOfProbes]",
"requestPath": "[parameters('healthProbes')[copyIndex('probes')].requestPath]"
}
}
}
]
}
}
]
}
To update a resource in an Azure Resource Manager template , you need to specify the updated resource in a second template that's either linked or included as a subtemplate using the Microsoft.Resources/deployments
resource type.若要更新 Azure 资源管理器模板中的资源,需要在使用
Microsoft.Resources/deployments
资源类型链接或包含为子模板的第二个模板中指定更新的资源。
First, you must reference the resource once in the template to create it and then reference the resource by the same name to update it later.
首先,您必须在模板中引用该资源一次以创建它,然后以相同的名称引用该资源以在以后更新它。 However, if two resources have the same name in a template, Resource Manager throws an exception.
但是,如果模板中的两个资源具有相同的名称,则资源管理器会引发异常。 To avoid this error, specify the updated resource in a second template that's either linked or included as a subtemplate using the Microsoft.Resources/deployments resource type.
为避免此错误,请在使用 Microsoft.Resources/deployments 资源类型链接或包含为子模板的第二个模板中指定更新的资源。
Second, you must either specify the name of the existing property to change or a new name for a property to add in the nested template.
其次,您必须指定要更改的现有属性的名称或要在嵌套模板中添加的属性的新名称。 You must also specify the original properties and their original values.
您还必须指定原始属性及其原始值。 If you fail to provide the original properties and values, Resource Manager assumes you want to create a new resource and deletes the original resource.
如果您未能提供原始属性和值,资源管理器会假定您要创建新资源并删除原始资源。
For example, if you have created resources from this 201-2-vms-loadbalancer-lbrules template , you just need to download the existing template from Load balancer----Settings---Export template.例如,如果您已经从这个 201-2-vms-loadbalancer-lbrules 模板创建了资源,您只需要从负载均衡器----设置---导出模板下载现有模板。 Then add the new loadBalancingRules and probes, edit the template to meet your requirements, then redeploy the edited full template with this command
然后添加新的 loadBalancingRules 和探针,编辑模板以满足您的要求,然后使用此命令重新部署已编辑的完整模板
New-AzResourceGroupDeployment -ResourceGroupName yourRG -mode Incremental -TemplateFile ".\template.json" -TemplateParameterFile ".\parameters.json"
For example,例如,
"loadBalancingRules": [
{
"name": "LBRule",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/frontendIPConfigurations/LoadBalancerFrontEnd')]"
},
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 5,
"protocol": "Tcp",
"enableTcpReset": false,
"loadDistribution": "Default",
"backendAddressPool": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/backendAddressPools/BackendPool1')]"
},
"probe": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/probes/tcpProbe')]"
}
}
},
{
"name": "LBRule-new",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/frontendIPConfigurations/LoadBalancerFrontEnd')]"
},
"frontendPort": 8080,
"backendPort": 8080,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 5,
"protocol": "Tcp",
"enableTcpReset": false,
"loadDistribution": "Default",
"backendAddressPool": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/backendAddressPools/BackendPool1')]"
},
"probe": {
"id": "[concat(resourceId('Microsoft.Network/loadBalancers', parameters('loadBalancers_myLB_name')), '/probes/tcpProbe')]"
}
}
}
],
"probes": [
{
"name": "tcpProbe",
"properties": {
"protocol": "Tcp",
"port": 80,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
},
{
"name": "tcpProbe-new",
"properties": {
"protocol": "Tcp",
"port": 8080,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
}
],
....
您需要从 ARM 模板运行 PowerShell 或 CLI
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.