【问题标题】:How to update existing routing rule in Azure Frontdoor using PowerShell?如何使用 PowerShell 更新 Azure Frontdoor 中的现有路由规则?
【发布时间】:2022-11-05 20:03:02
【问题描述】:

我需要将 Azure Frontdoor 中现有路由规则使用的后端池 (Maintenance) 更新为不同的现有后端池 (Maintenance2)。这是可以执行此操作的 UI 屏幕。有人可以建议如何通过 PowerShell 执行此操作。我已尝试通过 cmdlet (https://learn.microsoft.com/en-us/powershell/module/az.frontdoor/set-azfrontdoor?view=azps-9.0.1),但无法获得正确的命令集。

我已尝试通过 cmdlet (https://learn.microsoft.com/en-us/powershell/module/az.frontdoor/set-azfrontdoor?view=azps-9.0.1),但无法获得正确的命令集。

【问题讨论】:

    标签: automation azure-powershell azure-front-door


    【解决方案1】:

    为了将 Azure Front Door 中现有路由规则使用的后端池 (Poo1) 更新到不同的现有后端池 (Pool2)。

    1. 使用后端池 [Pool1/Pool2] 创建了 Front Door 环境,它们指向路由规则 池 1 -> 规则 1 和池 2 -> 规则 2

      点击规则1

      解决方法:

      1. 登录到 Powershell
      2. 标记到创建 Front Door 的当前订阅。使用以下命令

        az account set --subscription "******-****-****-****-*********"

        1. 使用此命令验证 Front Door 上的后端池

        az network front-door backend-pool list --front-door-name "FrontDoorName" --resource-group "ResoruceGroupName"

        1. 更新后端池为了规则1池1池2使用以下命令

        az network front-door routing-rule update --front-door-name "Front Door Name" --name "Rule Name" --resource-group "Resource Group Name" --backend-pool "New Backend Pool"

        例子:

        az network front-door routing-rule update --front-door-name "testfrontdoor" --name "Rule1" --resource-group "rg-testdemo" --backend-pool "pool2"

        输出:

        Front Door Rule1 上的结果输出

        现在 Rule1 指向后端池“Pool2”,而不是原来的“Pool1”。

    【讨论】:

      【解决方案2】:

      谢谢斯瓦纳。提供的解决方案在 CLI 中,问题是针对 powershell 的。

      我能够弄清楚如何在 PowerShell 中执行此操作。它需要使用 3 个 Azure PS cmdlet - Get-AzFrontDoor、New-AzFrontDoorRoutingRuleObject 和 Set-AzFrontDoor。它在后台工作的方式是,当对路由规则执行更新时,路由规则将被删除并随着更改重新创建。为了通过 PS 执行此操作,我们必须获取现有的前门属性、路由规则属性并将更改放入 New-AzFrontDoorRoutingRuleObject。最后使用 Set-AzFrontDoor 将更改应用到前门。

      **$subscription='Sub1'
      Select-AzSubscription $subscription
      $frontdoorName='Frontdoor1'
      $resourcegroupname='fdrrg'
      $MaintenanceBackPool='Maintenance2'
      $PrimaryBackPool='Maintenance1'
      $RoutingRuleName='Route1'
      
      #get the current frontdoor property object
      $frontdoorobj=Get-AzFrontDoor -ResourceGroupName $resourcegroupname -Name $frontdoorName
      
      #get the Routing Rules and filter the one which needs to be modified
      $RoutingRuleUpdate=$frontdoorobj.RoutingRules
      $RoutingRuleUpdate2=$RoutingRuleUpdate|Where-Object {$_.Name -contains $RoutingRuleName}
      
      #get the list of all frontendendpointIds as an array (this is required to account for more than 1 frontends/domains associated with the routing rule)
      #Perform string manipulation to get the frontend/domain name from the ID
      [String[]] $frontdoorHostnames=$RoutingRuleUpdate2.FrontendEndpointIds | ForEach-Object {"$PSItem" -replace '.*/'}
      
      #get the position of the Routing Rule (to be modified) in the Routing Rules collection
      $i=[array]::indexof($RoutingRuleUpdate.Name,$RoutingRuleName)
      
      #Update the Routing Rule object with the changes needed- in this case a different backendpool
      $updatedRouteObj=New-AzFrontDoorRoutingRuleObject -Name $RoutingRuleUpdate[$i].Name  -FrontDoorName $frontDoorName -ResourceGroupName $resourcegroupname -FrontendEndpointName $frontdoorHostnames -BackendPoolName $MaintenanceBackPool
      $RoutingRuleUpdate[$i]=$updatedRouteObj
      
      #Finally update the frontdoor object with the change in Routing Rule
      Set-AzFrontDoor -InputObject $frontdoorobj -RoutingRule $RoutingRuleUpdate 
      Write-Output "Successfully Updated RoutingRule:$RoutingRuleName to backendpool:$MaintenanceBackPool"**
      

      【讨论】:

        猜你喜欢
        • 2022-11-06
        • 2021-12-06
        • 2021-05-23
        • 2022-12-29
        • 1970-01-01
        • 2022-07-28
        • 2019-12-14
        • 2017-04-28
        • 1970-01-01
        相关资源
        最近更新 更多