# Lab 06: Implement Traffic Management

Configure and test both an Azure Load Balancer (Layer 4) and an Azure Application Gateway (Layer 7) for distributing traffic to web servers.

**Scenario:** Your organization hosts a public website. You need to load balance incoming traffic across multiple virtual machines (VMs) for high availability. Additionally, you want to route requests for images and videos to different backend servers based on the URL path.

**Key Concepts:**

* **Azure Load Balancer:** Distributes network traffic at Layer 4 (TCP/UDP). Provides high availability and scalability.
    
* **Azure Application Gateway:** A web traffic load balancer (Layer 7) that can make routing decisions based on URL path, host headers, and other HTTP attributes. Offers features like Web Application Firewall (WAF).
    
* **Frontend IP Configuration:** The public or private IP address that clients use to access the load-balanced service.
    
* **Backend Pool:** The group of VMs or other resources that receive the traffic from the load balancer.
    
* **Health Probes:** Checks the health of backend instances to ensure traffic is only sent to healthy servers.
    
* **Load Balancing Rules:** Define how incoming traffic is distributed to the backend pool based on port, protocol, and other criteria.
    
* **Listener (Application Gateway):** Listens for incoming traffic on a specific port and protocol.
    
* **Routing Rule (Application Gateway):** Connects a listener to a backend pool and defines how traffic is routed based on URL path or other criteria.
    

**Lab Tasks :**

![Diagram of the lab tasks.](https://raw.githubusercontent.com/MicrosoftLearning/AZ-104-MicrosoftAzureAdministrator/master/Instructions/media/az104-lab06-lb-architecture.png align="left")

## Job skills

* Task 1: Use a template to provision an infrastructure.
    
* Task 2: Configure an Azure Load Balancer.
    
* Task 3: Configure an Azure Application Gateway.
    

**Task 1: Provision Infrastructure (Template)**

1. **Download Lab Files:** Download the `\Allfiles\Lab06` files (template and parameters). These should include `az104-06-vms-template.json` and `az104-06-vms-parameters.json`.
    
2. **Deploy Custom Template:**
    
    * Search for and select "Deploy a custom template" and choose "Build your own template in the editor."
        
    * Click "Load file" and select `az104-06-vms-template.json` and click "Save."
        
    * Click "Edit parameters" and load the `az104-06-vms-parameters.json` file and click "Save."
        
    * **Basics:**
        
        * Subscription: (Select your subscription)
            
        * Password: (Provide a strong password)
            

![Screenshot of the create load balancer page.](https://raw.githubusercontent.com/MicrosoftLearning/AZ-104-MicrosoftAzureAdministrator/master/Instructions/media/az104-lab06-create-lb1.png align="left")

3. **Wait for Deployment:** The deployment will take about 5 minutes.  *Do not proceed until it's complete.* You can review the resources being created (1 VNet, 3 subnets, 2 VMs, 1 NSG).
    

**Task 2: Configure Azure Load Balancer**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740674906569/b187b64c-6d6b-4c26-bb4f-724e5a0447ba.png align="center")

1. **Create Load Balancer:** Search for and select "Load balancers" and click "+ Create."
    
    * **Basics:**
        
        * Subscription: (Your subscription)
            
        * Resource Group: `az104-rg6`
            
        * Name: `az104-lb`
            
        * SKU: `Standard`
            
        * Type: `Public`
            
        * Tier: `Regional`
            
    * Select **Next: Frontend IP configuration**.
        
2. **Frontend IP Configuration:**
    
    * Click "Add a frontend IP configuration."
        
        * Name: `az104-fe`
            
        * IP type: `IP address`
            
        * Click **Create new** under the *Public IP address* section. Use the following and click OK.
            
            * Name: `az104-lbpip`
                
            * SKU: Standard
                
            * Tier: Regional
                
            * Assignment: Static
                
    * Select **Next: Backend pools**.
        
    * ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740675212900/a5d8909e-f881-4921-afa6-54b663b03b40.png align="center")
        
3. **Backend Pool:**
    
    * Click "Add a backend pool."
        
        * Name: `az104-be`
            
        * Virtual network: `az104-06-vnet1`
            
        * Backend Pool Configuration: `NIC`
            
    * Select Add.
        
        * Add both `az104-06-vm0` and `az104-06-vm1` to the backend pool (check the boxes).
            
    * Click "Add" (to add the VMs)
        
    * Click Add (to create the backend pool).
        
    * Select **Next: Inbound Rules**.
        
    * ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740675332678/3c282dbe-4daa-4965-8426-58f8a6e176f9.png align="center")
        
4. **Load Balancing Rule:**
    
5. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740675438836/55af8484-4538-4f07-979e-396a9bd9cfea.png align="center")
    

* Click "+ Add a load balancing rule."
    
    * Name: `az104-lbrule`
        
    * IP Version: `IPv4`
        
    * Frontend IP address: `az104-fe`
        
    * Backend pool: `az104-be`
        
    * Protocol: `TCP`
        
    * Port: `80`
        
    * Backend port: `80`
        
    * Health probe: Click "Create new."
        
        * Name: `az104-hp`
            
        * Protocol: `TCP`
            
        * Port: `80`
            
        * Interval: `5`
            
        * Click "OK."
            
    * Session persistence: `None`
        
    * Idle timeout (minutes): `4`
        
    * TCP reset: `Disabled`
        
    * Floating IP: `Disabled` \*Outbound source network address translation (SNAT): `Recommended`
        
* **Review + create**: verify, and create.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740675771155/2493efe4-dfac-415d-8482-536c95510c5f.png align="center")

5. **Wait for Deployment and Go to Resource:** Wait for the load balancer to deploy, then click "Go to resource."
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740675883388/c4e8ca07-02ca-49c7-bb1c-a3a17f2a6076.png align="center")

5. **Test Load Balancer:** \* Locate the Load Balancer in the portal. \* In Settings, Select `Frontend IP Configuration`. \* Copy the `Public IP address` from the Frontend IP configuration. \* Open a new browser tab and paste the IP address. You should see "Hello World from az104-06-vm0" or "Hello World from az104-06-vm1." \* Refresh the page several times (or open a new *InPrivate/Incognito* window). The message should alternate between the two VMs, demonstrating load balancing.
    

**Task 3: Configure Azure Application Gateway**

![Diagram of the lab tasks.](https://raw.githubusercontent.com/MicrosoftLearning/AZ-104-MicrosoftAzureAdministrator/master/Instructions/media/az104-lab06-gw-architecture.png align="left")

1. **Add Subnet:**
    
    * Find `az104-06-vnet1` and under "Settings," select "Subnets."
        
    * Click "+ Subnet."
        
        * Name: `subnet-appgw`
            
        * Starting address: `10.60.3.224/27` (This provides enough addresses for the Application Gateway)
            
    * Click "Save."
        
2. **Create Application Gateway:**
    
    * Search for and select "Application gateways."
        
    * Click "+ Create."
        
    * **Basics:**
        
        * Subscription: (Your subscription)
            
        * Resource Group: `az104-rg6`
            
        * Application gateway name: `az104-appgw`
            
        * Tier: `Standard V2`
            
        * Enable autoscaling: `No`
            
        * Minimum instance count: `2`
            
        * Availability zone: `1` (default)
            
        * HTTP2: `Disabled`
            
        * Virtual network: `az104-06-vnet1`
            
        * Subnet: `subnet-appgw (10.60.3.224/27)`
            
    * Click "Next: Frontends &gt;."
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677286340/841ad5d6-e763-4c7c-a9a3-08b3177a35aa.png align="center")

3. **Frontend Configuration:**
    
    * Frontend IP address type: `Public`
        
    * Public IP address: Click "Add new."
        
        * Name: `az104-gwpip`
            
        * Click OK.
            
    * Click "Next: Backends &gt;."
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677218247/4d4fe334-87c4-4640-bd88-3b3acfad1158.png align="center")

4. **Backend Pools:**
    
    * Click "Add a backend pool."
        
        * Name: `az104-appgwbe`
            
        * Add backend pool without targets: `No`
            
        * Add the virtual machines: Select the NICs of both VM's: `az104-06-nic1 (10.60.1.4)` and `az104-06-nic2 (10.60.2.4)`
            
        * Click "Add."
            
    * Add an images backend pool:
        
        * Click "Add a backend pool."
            
        * Name: `az104-imagebe`
            
        * Add without targets: `No`
            
        * Add `az104-06-nic1(10.60.1.4)`
            
        * Click "Add".
            
    * Add a videos backend pool:
        
        * Click "Add a backend pool."
            
        * Name: `az104-videobe`
            
        * Add without targets: `No`
            
        * Add `az104-06-nic2(10.60.2.4)`
            
        * Click "Add".
            

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677203594/5bd9e7f8-18d6-441a-8785-3f282bdf04c8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677576318/7f04f8cd-c798-4178-a544-1fdf68241708.png align="center")

5. **Configuration (Routing Rule):**
    

* Click "Next: Configuration &gt;."
    
* Click **Add a routing rule**
    
* Click "Add a routing rule."
    
    * Rule name: `az104-gwrule`
        
    * Priority: `100`
        
    * Listener name: `az104-listener`
        
    * Frontend IP: `Public IPv4`
        
    * Protocol: `HTTP`
        
    * Port: `80`
        
    * Listener type: `Basic`
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677711712/f835f7e2-b27b-415a-a558-259c8bb6677c.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677873467/301c8779-d3cd-434c-9b7a-f58a6c8c87e8.png align="center")

6. witch to the Backend targets tab.
    

* Backend Target: `az104-appgwbe`
    
* Backend settings: Click "Add new."
    
    * Backend Setting Name: `az104-http`
        
    * Click "Add."
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677908598/6deaecb7-2743-482b-91a7-26671f34d710.png align="center")

7. Under the Path-based routing section, select **Add multiple targets to create a path-based rule**
    

* Add rule for images.
    
    * Path: `/image/*`
        
    * Target name: `images`
        
    * Backend settings: `az104-http`
        
    * Backend Target: `az104-imagebe`
        
    * Select Add.
        
* Add rule for videos.
    
* Path: `/video/*`
    
    * Target name: `videos`
        
    * Backend settings: `az104-http`
        
    * Backend Target: `az104-videobe`
        
    * Select Add.
        
* Click **Save**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740677990323/92029f29-29ef-493a-91ac-1cc6282365e2.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740678063662/e1323f14-dfbb-4431-a5bc-6e75e332abed.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740678099073/33f4cffc-c839-4a24-b94b-797407307f9f.png align="center")

8. **Review and Create:**
    

* Clik "Next: Tags &gt;" (no changes needed).
    
* Click "Next: Review + create &gt;," then click "Create."
    
* **Wait for Deployment:** This will take 5-10 minutes.
    

9. **Test Application Gateway:**
    

* Once deployed, go to the `az104-appgw` resource.
    
* Check Backend Health (under "Monitoring"): Ensure both servers in the backend pool show `Healthy`.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740678599405/a6dd1d65-cb1d-4646-8c5d-c6282776c388.png align="center")

* On the "Overview" blade, copy the `Frontend public IP address`.
    
* **Test Image Routing:** Open a new browser tab and go to `http://<frontend ip address>/image/`. You should be directed to the image server (vm1).
    
* **Test Video Routing:** Open a new browser tab and go to `http://<frontend ip address>/video/`. You should be directed to the video server (vm2).
    
* *You may need to use InPrivate/Incognito windows or clear your cache to ensure you're seeing the correct routing.*
    

**Here is the task 3 in summary:**

1. **Create Subnet**:
    
    * In the Azure portal, add a subnet (`subnet-appgw`) to `az104-06-vnet1` for the Application Gateway.
        
    * Ensure the subnet size is /27 or larger.
        
2. **Deploy Application Gateway**:
    
    * Use the Azure portal to create an Application Gateway (`az104-appgw`) with the following settings:
        
        * **Resource Group**: `az104-rg6`
            
        * **Region**: Same as Task 1
            
        * **Tier**: Standard V2
            
        * **Virtual Network**: `az104-06-vnet1`
            
        * **Subnet**: `subnet-appgw`
            
    * **Frontend IP**: Create a public IP address (`az104-gwpip`).
        
3. **Configure Backend Pools**:
    
    * Create backend pools to route traffic:
        
        * **az104-appgwbe**: General pool with both VMs (`az104-06-nic1` and `az104-06-nic2`).
            
        * **az104-imagebe**: Routes images to VM (`az104-06-nic1`).
            
        * **az104-videobe**: Routes videos to VM (`az104-06-nic2`).
            
4. **Add Routing Rules**:
    
    * Add routing rules for path-based traffic:
        
        * **Rule for Images**: Routes traffic with `/image/*` path to `az104-imagebe`.
            
        * **Rule for Videos**: Routes traffic with `/video/*` path to `az104-videobe`.
