Skip to content

Files

186 lines (137 loc) · 7.04 KB

quickstart-create-front-door-powershell.md

File metadata and controls

186 lines (137 loc) · 7.04 KB
title description services documentationcenter author ms.author manager ms.date ms.topic ms.service ms.workload ms.tgt_pltfrm ms.custom
Quickstart: Set up high availability with Azure Front Door - Azure PowerShell
This quickstart will show you how to use Azure Front Door to create a high availability and high-performance global web application using Azure PowerShell.
front-door
na
duongau
duau
KumudD
04/19/2021
quickstart
frontdoor
infrastructure-services
na
devx-track-azurepowershell, mode-api

Quickstart: Create a Front Door for a highly available global web application using Azure PowerShell

Get started with Azure Front Door by using Azure PowerShell to create a highly available and high-performance global web application.

The Front Door directs web traffic to specific resources in a backend pool. You defined the frontend domain, add resources to a backend pool, and create a routing rule. This article uses a simple configuration of one backend pool with two web app resources and a single routing rule using default path matching "/*".

:::image type="content" source="media/quickstart-create-front-door/environment-diagram.png" alt-text="Diagram of Front Door environment diagram using PowerShell." border="false":::

Prerequisites

  • An Azure account with an active subscription. Create an account for free.
  • Azure PowerShell installed locally or Azure Cloud Shell

[!INCLUDE updated-for-az]

[!INCLUDE cloud-shell-try-it.md]

Create resource group

In Azure, you allocate related resources to a resource group. You can either use an existing resource group or create a new one.

Create a resource group with New-AzResourceGroup:

New-AzResourceGroup -Name myResourceGroupFD -Location centralus

Create two instances of a web app

This quickstart requires two instances of a web application that run in different Azure regions. Both the web application instances run in Active/Active mode, so either one can take traffic. This configuration differs from an Active/Stand-By configuration, where one acts as a failover.

If you don't already have a web app, use the following script to set up two example web apps.

# Create first web app in Central US region.
$webapp1 = New-AzWebApp `
-Name "WebAppContoso-1" `
-Location centralus `
-ResourceGroupName myResourceGroupFD `
-AppServicePlan myAppServicePlanCentralUS

# Create second web app in South Central US region.
$webapp2 = New-AzWebApp `
-Name "WebAppContoso-2" `
-Location southcentralus `
-ResourceGroupName myResourceGroupFD `
-AppServicePlan myAppServicePlanEastUS

Create a Front Door

This section details how you can create and configure the following components of the Front Door:

  • A frontend object contains the Front Door default domain.
  • A backend pool is a set of equivalent backends to which Front Door load balances your client request.
  • A routing rule maps your frontend host and matching URL path pattern to a specific backend pool.

Create a frontend object

The frontend object configures the hostname for the Front Door. By default the hostname will have a suffix of *.azurefd.net.

# Create a unique name
$fdname = "contoso-frontend-$(Get-Random)"

#Create the frontend object
$FrontendEndObject = New-AzFrontDoorFrontendEndpointObject `
-Name "frontendEndpoint1" `
-HostName $fdname".azurefd.net"

Create the backend pool

The backend pool consists of the two web app created at the beginning of this quickstart. The health probe and load balancing settings defined in this step uses default values.

# Create backend objects that points to the hostname of the web apps
$backendObject1 = New-AzFrontDoorBackendObject `
-Address $webapp1.DefaultHostName
$backendObject2 = New-AzFrontDoorBackendObject `
-Address $webapp2.DefaultHostName

# Create a health probe object
$HealthProbeObject = New-AzFrontDoorHealthProbeSettingObject `
-Name "HealthProbeSetting"

# Create the load balancing setting object
$LoadBalancingSettingObject = New-AzFrontDoorLoadBalancingSettingObject `
-Name "Loadbalancingsetting" `
-SampleSize "4" `
-SuccessfulSamplesRequired "2" `
-AdditionalLatencyInMilliseconds "0"

# Create a backend pool using the backend objects, health probe, and load balancing settings
$BackendPoolObject = New-AzFrontDoorBackendPoolObject `
-Name "myBackendPool" `
-FrontDoorName $fdname `
-ResourceGroupName myResourceGroupFD `
-Backend $backendObject1,$backendObject2 `
-HealthProbeSettingsName "HealthProbeSetting" `
-LoadBalancingSettingsName "Loadbalancingsetting"

Create a routing rule

The routing rule maps the backend pool to the frontend domain and sets the default path matching value to "/*".

# Create a routing rule mapping the frontend host to the backend pool
$RoutingRuleObject = New-AzFrontDoorRoutingRuleObject `
-Name LocationRule `
-FrontDoorName $fdname `
-ResourceGroupName myResourceGroupFD `
-FrontendEndpointName "frontendEndpoint1" `
-BackendPoolName "myBackendPool" `
-PatternToMatch "/*"

Create the Front Door

Now that you've created the necessary objects, create the Front Door:

# Creates the Front Door
New-AzFrontDoor `
-Name $fdname `
-ResourceGroupName myResourceGroupFD `
-RoutingRule $RoutingRuleObject `
-BackendPool $BackendPoolObject `
-FrontendEndpoint $FrontendEndObject `
-LoadBalancingSetting $LoadBalancingSettingObject `
-HealthProbeSetting $HealthProbeObject

Once the deployment is successful, you can test it by following the steps in the next section.

Test the Front Door

Run the follow commands to obtain the hostname for the Front Door.

# Gets Front Door in resource group and output the hostname of the frontend domain.
$fd = Get-AzFrontDoor -ResourceGroupName myResourceGroupFD
$fd.FrontendEndpoints[0].Hostname

Open a web browser and enter the hostname obtain from the commands. The Front Door will direct your request to one of the backend resources.

:::image type="content" source="./media/quickstart-create-front-door-powershell/front-door-test-page.png" alt-text="Front Door test page":::

Clean up resources

When you no longer need the resources that you created with the Front Door, delete the resource group. When you delete the resource group, you also delete the Front Door and all its related resources.

To delete the resource group, call the Remove-AzResourceGroup cmdlet:

Remove-AzResourceGroup -Name myResourceGroupFD

Next steps

In this quickstart, you created a:

  • Front Door
  • Two web apps

To learn how to add a custom domain to your Front Door, continue to the Front Door tutorials.

[!div class="nextstepaction"] Add a custom domain