代码之家  ›  专栏  ›  技术社区  ›  Mike

从其他ARM模板将Url规则添加到Azure应用程序网关

  •  0
  • Mike  · 技术社区  · 7 年前

    我曾考虑过在我的基本模板拥有所有共享资源(数据库、应用服务计划和应用网关)的情况下使用链接模板,但即使使用链接模板,我认为我也无法向应用网关添加规则。

    使现代化 因此,我修改了模板,添加了对现有应用程序网关的引用,然后为新的BackEndPoolAddress和新的路径规则添加了变量。结果如下(仅缩写为相关部分):

     "variables": {
        "appGateway": "[reference(concat('Microsoft.Network/applicationGateways/', 'appGateWay-', uniqueString(resourceGroup().id)), '2017-06-01')]",
        "pathRule": {
          "name": "[concat(parameters('websiteName'), '- RoutingRule')]",
          "properties": {
            "paths": [
              "[parameters('routingRule')]"
            ],
            "backendAddressPool": {
              "id": "[concat(variables('appGateway').id, '/backendAddressPools/',parameters('websiteName'), 'BackEndPool')]"
            },
            "backendHttpSettings": {
              "id": "[variables('appGateway').backendHttpSettingsCollection[0]]"
            }
          }
        },
        "backendPool": {
          "name": "[concat(parameters('websiteName'), 'BackEndPool')]",
          "properties": {
            "IpAddress": "[reference(variables('webSiteName')).defaultHostName]"
          }
        }
      },
     "resources": [
      ...
        {
          "apiVersion": "2017-06-01",
          "name": "[variables('appGateway').name]",
          "type": "Microsoft.Network/applicationGateways",
          "location": "[resourceGroup().location]",
          "properties": {
            "backendAddressPools": "[concat(variables('appGateway').backendAddressPools, variables('backendPool'))]",
            "urlPathMaps": [
              {
                "name": "[variables('appGateway').urlPathMaps[0]]",
                "pathRules": "[concat(variables('appGateway').urlPathMaps[0].pathRules, variables('pathRule'))]"
              }
            ]
          }
        }
      ],
    

    但是,我得到一个模板验证错误,说我不能使用变量部分中的引用函数。如果我没有将其添加到变量部分,如何在变量部分为池和pathRule构建正确的路径?

    1 回复  |  直到 7 年前
        1
  •  1
  •   4c74356b41    7 年前

    您可以使用 reference()

    "outputs": {
        "httpListeners": {
            "type": "array",
            "value": "[reference('application_gateway_id', '2018-08-01', 'Full').properties.httpListeners]"
        }
    }
    

    将返回数组或httpListeners。您可以使用获取所有相关的应用程序网关属性并添加新的(附加)属性 concat() 并将结果指定给属性(属性):

    "httpListeners": "[concat(reference('application_gateway_id', '2018-08-01', 'Full').properties.httpListeners, variables('newListener'))]"
    

    您只需确保两个部署不会同时启动,一个可能会覆盖另一个

        2
  •  0
  •   Mike    6 年前

    echo "Logging into AKS Cluster"
    az aks get-credentials --resource-group $RESOURCEGROUP_NAME --name $AKSNAME
    
    echo "Get the created service's ip address"
    SERVICEIP=$(kubectl get service --namespace $AKSNAMESPACE $APPNAME-service -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
    
    
    echo "Creating backend pool - IP $SERVICEIP"
    az network application-gateway address-pool create \
      --gateway-name $APPGATEWAYNAME \
      --resource-group $RESOURCEGROUP_NAME \
      --name "$APPNAME-pool" \
      --servers $SERVICEIP
    
    echo "Creating probe"
    az network application-gateway probe create \
        --gateway-name $APPGATEWAYNAME \
        --name "$APPNAME-probe" \
        --path $APPPROBE \
        --resource-group $RESOURCEGROUP_NAME \
        --protocol Http \
        --resource-group $RESOURCEGROUP_NAME \
        --host-name-from-http-settings true 
    
    echo "Creating HTTP Settings"
    az network application-gateway http-settings create \
        --gateway-name $APPGATEWAYNAME \
        --name "$APPNAME-settings" \
        --port 80 \
        --resource-group $RESOURCEGROUP_NAME \
        --host-name-from-backend-pool \
        --probe "$APPNAME-probe" \
        --protocol Http
    
    
    
    echo "Creating URL Path Map"
    az network application-gateway url-path-map rule create \
        --gateway-name $APPGATEWAYNAME \
        --name "$APPNAME-rule" \
        --paths $RULEPATH \
        --path-map-name $RULENAME \
        --resource-group $RESOURCEGROUP_NAME \
        --http-settings "$APPNAME-settings" \
        --address-pool "$APPNAME-pool"