Implementing Application Gateway – Network Traffic Management

For this exercise, you will be creating the architecture shown in Figure 5.12. Our goal is to implement path-based routing.

If the request goes to the http://<frontendIP>/hello path, then you should get a response from the helloPool, which contains three servers each running the Apache web server. To validate the load balancing is working, you will customize the response of each server. Similarly, any request to the http://<frontendIP>/bye path will be handled by the byePool. The byePool servers are also running Apache, and their landing pages will be customized using scripting. You also have a jumpbox to manage the web servers.

You can use the PowerShell script provided here:

https://github.com/rithinskaria/azure-infra/blob/main/appgw-infra.ps1

FIGURE 5.12 Application Gateway reference architecture

to deploy all the components except the Application Gateway. Make sure that you change the username and password for the VMs as per your requirements. The script will return the FQDN of the jumpbox and the private IP addresses of all the VM that you need to add behind the Application Gateway. See Exercise 5.2.

EXERCISE 5.2
 Implementing Azure Application Gateway

  1. If you have successfully run the PowerShell script, all resources will be deployed. SSH to the jumpbox using the public IP address/FQDN of the VM.
  2. Once you are in the jumpbox VM and run the command nano script.sh, this will open the nano text editor, and you have to paste the following script. If the IP addresses of the VM don’t match with the logic in the script, change that accordingly.

   #!/bin/bash
   sudo apt update -y
   sudo apt install sshpass -y
   echo “Setting up helloPool VMs”
   for i in {1..3}
   do
   j=$(($i + 3))
   ip=”10.0.1.$j”
   sshpass -p “VMP@55w0rd” \
   ssh -o StrictHostKeyChecking=no rithin@$ip bash -c  \
   “‘export VAR=$i
   printenv | grep VAR
   echo “Setting up hello-0$i VM”
   sudo apt install apache2 -y
   sudo chmod -R -v 777 /var/www/
   mkdir /var/www/html/hello
   echo “HelloPool wants to say hi from hello-0$i”> /var/www/html/hello/hello.html
   exit
   ‘”
   done
   echo “Setting up byePool VMs”
   for i in {1..3}
   do
   j=$(($i + 3))
   ip=”10.0.2.$j”
   sshpass -p “VMP@55w0rd” \
   ssh -o StrictHostKeyChecking=no rithin@$ip bash -c  \
   “‘export VAR=$i
   printenv | grep VAR
   echo “Setting up bye-0$i VM”
   sudo apt install apache2 -y
   sudo chmod -R -v 777 /var/www/
   mkdir /var/www/html/bye
   echo “ByePool wants to say bye from bye-0$i”> /var/www/html/bye/bye.html
   exit
   ‘”
   done

  1. Hit Ctrl+X, press y, and then hit Enter to save the file. Once the file is saved, grant execute permissions by running chmod +x script.sh. Then you may run the script by entering ./script.sh.
  2. The script may take some time to complete the execution. Once executed, you can send curl requests from the jumpbox to the individual web servers and verify the response.
  1. Now you need to create the Application Gateway, and for that you can navigate to the Azure portal and search for Application Gateway. Click Application Gateways from the search results.
  2. From the Load Balancing – Help Me Choose (Preview) | Application Gateway window, click Create Application Gateway or simply Create in the toolbar.
  3. In the wizard, you need to provide the following details in the Basics tab:
    • Subscription: Select the subscription.
    • Resource Group: Select the resource group. Create a new one if required.
    • Application gateway name: Give a name for the Application Gateway.
    • Region: Select East US as the PowerShell script created the resources in East US. If you have created the resources in another region, select the region accordingly.
    • Tier: Choose the default tier of Standard V2.
    • Enable autoscaling: Set this to Yes or No. If you select Yes, then you have to specify the min and max number of instances. If you disable autoscaling, you can specify the instance count.
    • Availability zone: Set to None.
    • HTTP2: Disabled.
    • Virtual Network: Select the virtual network where our web servers are deployed. The wizard will ask you to select the subnet. Application Gateway requires a dedicated subnet for the deployment; since you have created this infrastructure using the script, you haven’t added the subnet. Nevertheless, you can click Manage Subnet Configuration and add a new subnet named ApplicationGateway. The CIDR block needs to be at least /26. Once the subnet is created, select the subnet.

Leave a Reply

Your email address will not be published. Required fields are marked *