Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80e138f

Browse files
committedNov 28, 2017
new vmss tutorial
1 parent 8cfa289 commit 80e138f

16 files changed

+556
-0
lines changed
 

‎articles/application-gateway/TOC.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
### [Resource Manager template](application-gateway-create-gateway-arm-template.md)
2020
### [Azure CLI](application-gateway-create-gateway-cli.md)
2121
# How to
22+
## Create application gateway with VMSS
23+
### [Azure portal](tutorial-create-vmss-portal.md)
24+
### [Azure PowerShell](tutorial-create-vmss-powershell.md)
25+
### [Azure CLI](tutorial-create-vmss-cli.md)
2226
## Configure web application firewall
2327
### [Azure portal](application-gateway-web-application-firewall-portal.md)
2428
### [Azure PowerShell](application-gateway-web-application-firewall-powershell.md)
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: Create an application gateway with a virtual machine scale set - Azure CLI | Microsoft Docs
3+
description: Learn how to create an application gateway with a virtual machine scale set using the Azure CLI.
4+
services: application-gateway
5+
author: davidmu1
6+
manager: timlt
7+
editor: tysonn
8+
9+
ms.service: application-gateway
10+
ms.topic: article
11+
ms.workload: infrastructure-services
12+
ms.date: 11/15/2017
13+
ms.author: davidmu
14+
15+
---
16+
# Create an application gateway with a virtual machine scale set using the Azure CLI
17+
18+
You can use the Azure CLI to create an [application gateway](application-gateway-introduction.md) that uses a [virtual machine scale set](../virtual-machine-scale-sets/virtual-machine-scale-sets-overview.md) for backend servers. In this example, the scale set contains two virtual machine instances that are added to the default backend pool of the application gateway.
19+
20+
In this article, you learn how to
21+
22+
> [!div class="checklist"]
23+
> * Create a virtual machine scale set
24+
> * Create an application gateway
25+
> * Add servers to the default backend pool
26+
27+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
28+
29+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
30+
31+
If you choose to install and use the CLI locally, this quickstart requires that you are running the Azure CLI version 2.0.4 or later. To find the version, run `az --version`. If you need to install or upgrade, see [Install Azure CLI 2.0](/cli/azure/install-azure-cli).
32+
33+
## Create a resource group
34+
35+
Create a resource group using [az group create](/cli/azure/group#create). An Azure resource group is a logical container into which Azure resources are deployed and managed.
36+
37+
The following example creates a resource group named *myResourceGroupAG* in the *eastus* location.
38+
39+
```azurecli-interactive
40+
az group create --name myResourceGroupAG --location eastus
41+
```
42+
43+
## Create a virtual network, subnets, and public IP address
44+
45+
You can create the virtual network and the backend subnet by using [az network vnet create](/cli/azure/network/vnet#az_net). You can add the subnet named *myAGSubnet* that's needed by the application gateway by using [az network vnet subnet create](/cli/azure/network/vnet/subnet#az_network_vnet_subnet_create). Create the public IP address named *myAGPublicIPAddress* by using [az network public-ip create](/cli/azure/public-ip#az_network_public_ip_create).
46+
47+
```azurecli-interactive
48+
az network vnet create \
49+
--name myVNet \
50+
--resource-group myResourceGroupAG \
51+
--location eastus \
52+
--address-prefix 10.0.0.0/16 \
53+
--subnet-name myBackendSubnet \
54+
--subnet-prefix 10.0.1.0/24
55+
az network vnet subnet create \
56+
--name myAGSubnet \
57+
--resource-group myResourceGroupAG \
58+
--vnet-name myVNet \
59+
--address-prefix 10.0.2.0/24
60+
az network public-ip create \
61+
--resource-group myResourceGroupAG \
62+
--name myAGPublicIPAddress
63+
```
64+
65+
## Create a virtual machine scale set
66+
67+
In this example, you create a virtual machine scale set that provides servers for the default backend pool in the application gateway. The virtual machines in the scale set are associated with the *myBackendSubnet* subnet. You can use [az vmss create](/cli/azure/vmss#az_vmss_create) to create the scale set.
68+
69+
```azurecli-interactive
70+
az vmss create \
71+
--name myvmss \
72+
--resource-group myResourceGroupAG \
73+
--image UbuntuLTS \
74+
--admin-username azureuser \
75+
--admin-password Azure123456! \
76+
--instance-count 2 \
77+
--vnet-name myVNet \
78+
--subnet myBackendSubnet \
79+
--vm-sku Standard_DS2 \
80+
--upgrade-policy-mode Automatic
81+
```
82+
83+
### Install NGINX
84+
85+
In your current shell, create a file named customConfig.json and paste the following configuration. You can use any editor you wish to create the file in the Cloud Shell. Enter `sensible-editor cloudConfig.json` to see a list of available editors to create the file.
86+
87+
```json
88+
{
89+
"fileUris": ["https://raw.githubusercontent.com/davidmu1/samplescripts/master/install_nginx.sh"],
90+
"commandToExecute": "./install_nginx.sh"
91+
}
92+
```
93+
94+
Run this command in the shell window:
95+
96+
```azurecli-interactive
97+
az vmss extension set \
98+
--publisher Microsoft.Azure.Extensions \
99+
--version 2.0 \
100+
--name CustomScript \
101+
--resource-group myResourceGroupAG \
102+
--vmss-name myvmss \
103+
--settings @cloudConfig.json
104+
```
105+
106+
## Create an application gateway
107+
108+
### Get the IP addresses of the instances
109+
110+
Use [az vmss nic list](/cli/azure/vmss/nic#az_vmss_nic_list) to get the private IP address of each virtual machine in the scale set. After running the command, record the private IP addresses for each virtual machine.
111+
112+
```azurecli-interactive
113+
az vmss nic list \
114+
--vmss-name myvmss \
115+
--resource-group myResourceGroupAG | grep "privateIpAddress"
116+
```
117+
118+
### Create the application gateway
119+
120+
Now that you created the necessary supporting resources, use [az network application-gateway create](/cli/azure/application-gateway#create) to create the application gateway. When you create an application gateway using the Azure CLI, you specify configuration information, such as capacity, sku, and HTTP settings. Use the two IP addresses that you recorded for the value of the `--servers` parameter.
121+
122+
```azurecli-interactive
123+
az network application-gateway create \
124+
--name myAppGateway \
125+
--location eastus \
126+
--resource-group myResourceGroupAG \
127+
--vnet-name myVNet \
128+
--subnet myAGsubnet \
129+
--capacity 2 \
130+
--sku Standard_Medium \
131+
--http-settings-cookie-based-affinity Disabled \
132+
--frontend-port 80 \
133+
--http-settings-port 80 \
134+
--http-settings-protocol Http \
135+
--servers 10.0.1.5 10.0.1.7 \
136+
--public-ip-address myAGPublicIPAddress
137+
```
138+
139+
It may take several minutes for the application gateway to be created. After the application gateway is created, you can see these new features of it:
140+
141+
- *appGatewayBackendPool* - An application gateway must have at least one backend address pool.
142+
- *appGatewayBackendHttpSettings* - Specifies that port 80 and an HTTP protocol is used for communication.
143+
- *appGatewayHttpListener* - The default listener associated with *appGatewayBackendPool*.
144+
- *appGatewayFrontendIP* - Assigns *myAGPublicIPAddress* to *appGatewayHttpListener*.
145+
- *rule1* - The default routing rule that is associated with *appGatewayHttpListener*.
146+
147+
## Test the application gateway
148+
149+
1. Use [az network public-ip show](/cli/azure/network/public-ip#az_network_public_ip_show) to get the public IP address of the application gateway.
150+
151+
```azurepowershell-interactive
152+
az network public-ip show \
153+
--resource-group myResourceGroupAG \
154+
--name myAGPublicIPAddress \
155+
--query [ipAddress] \
156+
--output tsv
157+
```
158+
159+
2. Copy the public IP address, and then paste it into the address bar of your browser.
160+
161+
![Test base URL in application gateway](./media/tutorial-create-vmss-cli/tutorial-nginxtest.png)
162+
163+
## Next steps
164+
165+
In this tutorial, you learned how to:
166+
167+
> [!div class="checklist"]
168+
> * Create a virtual machine scale set
169+
> * Create an application gateway
170+
> * Add servers to the default backend pool
171+
172+
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
title: Create an application gateway with a virtual machine scale set - Azure portal | Microsoft Docs
3+
description: Learn how to create an application gateway with a virtual machine scale set using the Azure portal.
4+
services: application-gateway
5+
author: davidmu1
6+
manager: timlt
7+
editor: tysonn
8+
tags: azure-resource-manager
9+
10+
ms.service: application-gateway
11+
ms.topic: article
12+
ms.workload: infrastructure-services
13+
ms.date: 11/07/2017
14+
ms.author: davidmu
15+
16+
---
17+
# Create an application gateway and virtual machine scale set using the Azure portal
18+
19+
You can use the Azure portal to create an [application gateway](application-gateway-introduction.md) that uses a [virtual machine scale set](../virtual-machine-scale-sets/virtual-machine-scale-sets-overview.md) for backend servers. In this example, the scale set contains two virtual machine instances that are added to the default backend pool of the application gateway.
20+
21+
In this article, you learn how to
22+
23+
> [!div class="checklist"]
24+
> * Create a virtual machine scale set
25+
> * Create an application gateway
26+
> * Add servers to the default backend pool
27+
28+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
29+
30+
## Log in to Azure
31+
32+
Log in to the Azure portal at [http://portal.azure.com](http://portal.azure.com)
33+
34+
## Create a virtual machine scale set
35+
36+
When you create a virtual machine scale set, a virtual network is automatically created for you. In this example, the scale set and the application gateway are in the same virtual network, so you create the scale set first.
37+
38+
1. Click **Create a resource** found on the upper left-hand corner of the Azure portal.
39+
2. Click **Compute** and then select **Virtual machine scale set** in the Featured list.
40+
3. Enter these values for the virtual machine scale set:
41+
42+
- *myvmss* - for the name of the scale set. The name must be lowercase letters.
43+
- *myResourceGroupAG* - for the name of new the resource group.
44+
- *azureuser* - for the user name.
45+
- *Azure123456!* - for the password.
46+
- *2* - for the instance count.
47+
- *myVMSSPublicIPAddress* - for the name of the public IP address associated with the scale set. This resource is required to create the scale set, but is not used in the example.
48+
- *myvmss* - for the domain name label.
49+
50+
![Create new virtual machine scale set](./media/tutorial-create-vmss-portal/tutorial-vmss.png)
51+
52+
4. Accept all other default values and then click **Create**.
53+
54+
### Install IIS
55+
56+
1. Open the interactive shell and make sure that it is set to **PowerShell**.
57+
58+
![Install custom extension](./media/tutorial-create-vmss-portal/tutorial-cloudshell.png)
59+
60+
2. Run the following commands to install IIS on the virtual machine instances in the scale set:
61+
62+
```azurepowershell-interactive
63+
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/davidmu1/samplescripts/master/appgatewayurl.ps1");
64+
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }
65+
66+
$vmss = Get-AzureRmVmss -ResourceGroupName myResourceGroupAG -VMScaleSetName myvmss
67+
Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmss `
68+
-Name "customScript" `
69+
-Publisher "Microsoft.Compute" `
70+
-Type "CustomScriptExtension" `
71+
-TypeHandlerVersion 1.8 `
72+
-Setting $publicSettings
73+
74+
Update-AzureRmVmss `
75+
-ResourceGroupName myResourceGroupAG `
76+
-Name myvmss `
77+
-VirtualMachineScaleSet $vmss
78+
```
79+
80+
3. The previous PowerShell commands only update the model of the scale set. To update the instances, click **All resources**, click **myvmss**, and then click **Instances**.
81+
82+
4. Select all instances and then click **Upgrade**.
83+
84+
![Upgrade instances with IIS](./media/tutorial-create-vmss-portal/tutorial-upgrade.png)
85+
86+
## Create a subnet
87+
88+
1. Click **All resources** in the left-hand menu, and then click **myvmssVnet** from the resources list.
89+
2. Click **Subnets** and then click **Subnet**.
90+
91+
![Create subnet](./media/tutorial-create-vmss-portal/tutorial-subnet.png)
92+
93+
3. Enter *myAGSubnet* for the name of the subnet and then click **OK**.
94+
95+
## Create an application gateway
96+
97+
1. Click **Create a resource**.
98+
2. Click **Networking** and then select **Application Gateway** in the Featured list.
99+
3. Enter these values for the application gateway:
100+
101+
- *myAppGateway* - for the name of the application gateway.
102+
- Select **Use existing** and then select *myResourceGroupAG*.
103+
104+
![Create new application gateway](./media/tutorial-create-vmss-portal/tutorial-create.png)
105+
106+
4. Accept the default values for the other settings and then click **OK**.
107+
5. Click **Choose a virtual network**, and then click **mymssVnet**.
108+
6. Make sure that the subnet to is set to *myAGSubnet*, click **Choose a public IP address**, and then click **Create new**.
109+
7. Enter the name of the public IP address. In this example, the public IP address is named *myAGPublicIPAddress*. Accept the default values for the other settings and then click **OK**.
110+
111+
![Choose public IP address](./media/tutorial-create-vmss-portal/tutorial-public-ip.png)
112+
113+
8. Accept the default values for the Listener configuration, leave the Web application firewall disabled, and then click **OK**.
114+
9. Review the settings on the summary page, and then click **OK** to create the public IP address and application gateway. It may take several minutes for the application gateway to be created, wait until the deployment finishes successfully before moving on to the next section.
115+
116+
## Add servers to the default backend pool
117+
118+
1. Find the IP addresses of the virtual machines in the scale set. Click **All resources**, select **myvmssVnet** in the resources list, and then click **Overview**.
119+
2. Record the IP addresses to use later when you add the scale set instances to the backend pools. In this example, the IP addresses are *10.0.0.4* and *10.0.0.5*.
120+
121+
![Record IP address](./media/tutorial-create-vmss-portal/tutorial-ip-addresses.png)
122+
123+
3. Click **All resources** and then click **myAppGateway**.
124+
4. Click **Backend pools**. A default pool was automatically created with the application gateway. Click **appGatewayBackendPool**.
125+
5. Click **Add target** to add the two IP addresses that you recorded to appGatewayBackendPool.
126+
127+
![Add backend servers](./media/tutorial-create-vmss-portal/tutorial-backend-pool.png)
128+
129+
6. Click **Save**.
130+
131+
## Test the application gateway
132+
133+
1. Click **All resources**, and then click **myAGPublicIPAddress**.
134+
135+
![Record application gateway public IP address](./media/tutorial-create-vmss-portal/tutorial-ag-address.png)
136+
137+
2. Copy the public IP address, and then paste it into the address bar of your browser.
138+
139+
![Test base URL in application gateway](./media/tutorial-create-vmss-portal/tutorial-iistest.png)
140+
141+
## Next steps
142+
143+
In this tutorial, you learned how to:
144+
145+
> [!div class="checklist"]
146+
> * Create a virtual machine scale set
147+
> * Create an application gateway
148+
> * Add servers to the default backend pool
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
---
2+
title: Create an application gateway with a virtual machine scale set - Azure PowerShell | Microsoft Docs
3+
description: Learn how to create an application gateway with a virtual machine scale set using Azure PowerShell.
4+
services: application-gateway
5+
author: davidmu1
6+
manager: timlt
7+
editor: tysonn
8+
9+
ms.service: application-gateway
10+
ms.topic: article
11+
ms.workload: infrastructure-services
12+
ms.date: 11/14/2017
13+
ms.author: davidmu
14+
15+
---
16+
# Create an application gateway and virtual machine scale set using Azure PowerShell
17+
18+
You can use Azure PowerShell to create an [application gateway](application-gateway-introduction.md) that uses a [virtual machine scale set](../virtual-machine-scale-sets/virtual-machine-scale-sets-overview.md) for backend servers. In this example, the scale set contains two virtual machine instances that are added to the default backend pool of the application gateway.
19+
20+
In this article, you learn how to
21+
22+
> [!div class="checklist"]
23+
> * Create a virtual machine scale set
24+
> * Create an application gateway
25+
> * Add servers to the default backend pool
26+
27+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
28+
29+
[!INCLUDE [cloud-shell-powershell.md](../../includes/cloud-shell-powershell.md)]
30+
31+
If you choose to install and use the PowerShell locally, this tutorial requires the Azure PowerShell module version 3.6 or later. To find the version, run `Get-Module -ListAvailable AzureRM`. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azurerm-ps). If you are running PowerShell locally, you also need to run `Login-AzureRmAccount` to create a connection with Azure.
32+
33+
## Create a resource group
34+
35+
Create an Azure resource group using [New-AzureRmResourceGroup](/powershell/module/azurerm.resources/new-azurermresourcegroup). A resource group is a logical container into which Azure resources are deployed and managed.
36+
37+
```azurepowershell-interactive
38+
New-AzureRmResourceGroup -Name myResourceGroupAG -Location eastus
39+
```
40+
41+
## Create a virtual network, subnets, and public IP address
42+
43+
Create the subnet configurations using [New-AzureRmVirtualNetworkSubnetConfig](/powershell/module/azurerm.network/new-azurermvirtualnetworksubnetconfig). Create the virtual network using [New-AzureRmVirtualNetwork](/powershell/module/azurerm.network/new-azurermvirtualnetwork) with the subnet configurations. And finally, create the public IP address using [New-AzureRmPublicIpAddress](/powershell/module/azurerm.network/new-azurermpublicipaddress). These resources are used to provide network connectivity to the application gateway and its associated resources.
44+
45+
```azurepowershell-interactive
46+
$backendSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
47+
-Name myBackendSubnet `
48+
-AddressPrefix 10.0.1.0/24
49+
$agSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
50+
-Name myAGSubnet `
51+
-AddressPrefix 10.0.2.0/24
52+
$vnet = New-AzureRmVirtualNetwork `
53+
-ResourceGroupName myResourceGroupAG `
54+
-Location eastus `
55+
-Name myVNet `
56+
-AddressPrefix 10.0.0.0/16 `
57+
-Subnet $backendSubnetConfig, $agSubnetConfig
58+
$pip = New-AzureRmPublicIpAddress `
59+
-ResourceGroupName myResourceGroupAG `
60+
-Location eastus `
61+
-Name myAGPublicIPAddress `
62+
-AllocationMethod Dynamic
63+
```
64+
65+
## Create a virtual machine scale set
66+
67+
In this example, you create a virtual machine scale set to provide servers for the backend pool in the application gateway. You can use [New-AzureRmVmssIpConfig](/powershell/module/azurerm.compute/new-azurermvmssipconfig) and [New-AzureRmVmssConfig](/powershell/module/azurerm.compute/new-azurermvmssconfig) to configure the scale set to use the *myBackendSubnet* subnet and to specify that the scale set should contain two virtual machine instances.
68+
69+
You use [Set-AzureRmVmssStorageProfile](/powershell/module/azurerm.compute/set-azurermvmssstorageprofile) and [Set-AzureRmVmssOsProfile](/powershell/module/azurerm.compute/set-azurermvmssosprofile) to specify and configure the operating system on the virtual machines. To configure the network interface for the virtual machines, you can use [Add-AzureRmVmssNetworkInterfaceConfiguration](/powershell/module/azurerm.compute/add-azurermvmssnetworkinterfaceconfiguration). And finally, you can use [New-AzureRmVmss](/powershell/module/azurerm.compute/new-azurermvmss) to create the scale set.
70+
71+
```azurepowershell-interactive
72+
$ipConfig = New-AzureRmVmssIpConfig `
73+
-Name myVmssIPConfig `
74+
-SubnetId $vnet.Subnets[0].Id
75+
$vmssConfig = New-AzureRmVmssConfig `
76+
-Location eastus `
77+
-SkuCapacity 2 `
78+
-SkuName Standard_DS2 `
79+
-UpgradePolicyMode Automatic
80+
Set-AzureRmVmssStorageProfile $vmssConfig `
81+
-ImageReferencePublisher MicrosoftWindowsServer `
82+
-ImageReferenceOffer WindowsServer `
83+
-ImageReferenceSku 2016-Datacenter `
84+
-ImageReferenceVersion latest
85+
Set-AzureRmVmssOsProfile $vmssConfig `
86+
-AdminUsername azureuser `
87+
-AdminPassword "Azure123456!" `
88+
-ComputerNamePrefix myvmss
89+
Add-AzureRmVmssNetworkInterfaceConfiguration `
90+
-VirtualMachineScaleSet $vmssConfig `
91+
-Name myVmssNetConfig `
92+
-Primary $true `
93+
-IPConfiguration $ipConfig
94+
New-AzureRmVmss `
95+
-ResourceGroupName myResourceGroupAG `
96+
-Name myvmss `
97+
-VirtualMachineScaleSet $vmssConfig
98+
```
99+
100+
### Install IIS
101+
102+
```azurepowershell-interactive
103+
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/davidmu1/samplescripts/master/appgatewayurl.ps1");
104+
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }
105+
106+
$vmss = Get-AzureRmVmss -ResourceGroupName myResourceGroupAG -VMScaleSetName myvmss
107+
Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmss `
108+
-Name "customScript" `
109+
-Publisher "Microsoft.Compute" `
110+
-Type "CustomScriptExtension" `
111+
-TypeHandlerVersion 1.8 `
112+
-Setting $publicSettings
113+
114+
Update-AzureRmVmss `
115+
-ResourceGroupName myResourceGroupAG `
116+
-Name myvmss `
117+
-VirtualMachineScaleSet $vmss
118+
```
119+
120+
## Create an application gateway
121+
122+
### Create the IP configurations
123+
124+
Use [New-AzureRmApplicationGatewayIPConfiguration](/powershell/module/azurerm.network/new-azurermapplicationgatewayipconfiguration) to create the configuration that associates the subnet that you previously created with the application gateway. Use [New-AzureRmApplicationGatewayFrontendIPConfig](/powershell/module/azurerm.network/new-azurermapplicationgatewayfrontendipconfig) to create the configuration that assigns the public IP address that you also previously created to the application gateway.
125+
126+
```azurepowershell-interactive
127+
$subnet=$vnet.Subnets[1]
128+
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration `
129+
-Name myAGIPConfig `
130+
-Subnet $subnet
131+
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig `
132+
-Name myAGFrontendIPConfig `
133+
-PublicIPAddress $pip
134+
```
135+
136+
### Create the frontend port
137+
138+
Use [New-AzureRmApplicationGatewayFrontendPort](/powershell/module/azurerm.network/new-azurermapplicationgatewayfrontendport) to assign port 80 to be used to access the application gateway.
139+
140+
```azurepowershell-interactive
141+
$frontendport = New-AzureRmApplicationGatewayFrontendPort `
142+
-Name myFrontendPort `
143+
-Port 80
144+
```
145+
146+
### Create the default backend pool
147+
148+
1. Use [Get-AzureRmNetworkInterface](/powershell/module/azurerm.network/get-azurermnetworkinterface) to get the private IP address of each virtual machine in the scale set. After running the command, record the private IP addresses for each virtual machine.
149+
150+
```azurepowershell-interactive
151+
Get-AzureRmNetworkInterface -ResourceGroupName myResourceGroupAG -VirtualMachineScaleSetName myvmss | ForEach-Object {$_.ipConfigurations[0].PrivateIPAddress}
152+
```
153+
154+
2. Use [New-AzureRmApplicationGatewayBackendAddressPool](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendaddresspool) to create the backend address pool for the application gateway. Configure the settings for the backend address pools using [New-AzureRmApplicationGatewayBackendHttpSettings](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendhttpsettings). Change the server IP addresses to the two that you previously recorded.
155+
156+
```azurepowershell-interactive
157+
$defaultPool = New-AzureRmApplicationGatewayBackendAddressPool `
158+
-Name appGatewayBackendPool `
159+
-BackendIPAddresses 10.0.0.4, 10.0.0.5
160+
$poolSettings = New-AzureRmApplicationGatewayBackendHttpSettings `
161+
-Name myPoolSettings `
162+
-Port 80 `
163+
-Protocol Http `
164+
-CookieBasedAffinity Enabled `
165+
-RequestTimeout 120
166+
```
167+
168+
### Create the default listener and rule
169+
170+
Listeners are required to enable the application gateway to route traffic appropriately to the backend address pools. In this example, you create a basic listener that listens for traffic at the root URL.
171+
172+
Create a listener using [New-AzureRmApplicationGatewayHttpListener](/powershell/module/azurerm.network/new-azurermapplicationgatewayhttplistener) with the frontend configuration and frontend port that you previously created. A rule is required for the listener to know which backend pool to use for incoming traffic. Use [New-AzureRmApplicationGatewayRequestRoutingRule](/powershell/module/azurerm.network/new-azurermapplicationgatewayrequestroutingrule) to create a basic rule named *rule1*.
173+
174+
```azurepowershell-interactive
175+
$defaultlistener = New-AzureRmApplicationGatewayHttpListener `
176+
-Name mydefaultListener `
177+
-Protocol Http `
178+
-FrontendIPConfiguration $fipconfig `
179+
-FrontendPort $frontendport
180+
$frontendRule = New-AzureRmApplicationGatewayRequestRoutingRule `
181+
-Name rule1 `
182+
-RuleType Basic `
183+
-HttpListener $defaultlistener `
184+
-BackendAddressPool $defaultPool `
185+
-BackendHttpSettings $poolSettings
186+
```
187+
188+
### Create the application gateway
189+
190+
Now that you created the necessary supporting resources, use [New-AzureRmApplicationGatewaySku](/powershell/module/azurerm.network/new-azurermapplicationgatewaysku) to specify parameters for the application gateway, and then use [New-AzureRmApplicationGateway](/powershell/module/azurerm.network/new-azurermapplicationgateway) to create it.
191+
192+
```azurepowershell-interactive
193+
$sku = New-AzureRmApplicationGatewaySku `
194+
-Name Standard_Medium `
195+
-Tier Standard `
196+
-Capacity 2
197+
$appgw = New-AzureRmApplicationGateway `
198+
-Name myAppGateway `
199+
-ResourceGroupName myResourceGroupAG `
200+
-Location eastus `
201+
-BackendAddressPools $defaultPool `
202+
-BackendHttpSettingsCollection $poolSettings `
203+
-FrontendIpConfigurations $fipconfig `
204+
-GatewayIpConfigurations $gipconfig `
205+
-FrontendPorts $frontendport `
206+
-HttpListeners $defaultlistener `
207+
-RequestRoutingRules $frontendRule `
208+
-Sku $sku
209+
```
210+
211+
## Test the application gateway
212+
213+
1. Use [Get-AzureRmPublicIPAddress](/powershell/module/azurerm.network/get-azurermpublicipaddress) to get the public IP address of the application gateway.
214+
215+
```azurepowershell-interactive
216+
Get-AzureRmPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
217+
```
218+
219+
2. Copy the public IP address, and then paste it into the address bar of your browser.
220+
221+
![Test base URL in application gateway](./media/tutorial-create-vmss-powershell/tutorial-iistest.png)
222+
223+
## Next steps
224+
225+
In this tutorial, you learned how to:
226+
227+
> [!div class="checklist"]
228+
> * Create a virtual machine scale set
229+
> * Create an application gateway
230+
> * Add servers to the default backend pool
231+
232+

0 commit comments

Comments
 (0)
Please sign in to comment.