/azure-web-server-load-balancer

A simple demo to run a network load balancer for load balancing traffic to web servers running Nginx on Azure VM.

Primary LanguageBicep

Azure Network Load Balancer for Web Servers

A simple demo to run a network load balancer for load balancing traffic to web servers running Nginx on Azure VM.

๐ŸŽฏ Solution

Miztiik Automation - Azure Network Load Balancer for Web Servers

  1. ๐Ÿงฐ Prerequisites

    This demo, along with its instructions, scripts, and Bicep template, has been specifically designed to be executed in the northeurope region. However, with minimal modifications, you can also try running it in other regions of your choice (the specific steps for doing so are not covered in this context)

  2. โš™๏ธ Setting up the environment

    • Get the application code

      git clone https://github.com/miztiik/azure-web-server-load-balancer.git
      cd azure-web-server-load-balancer
  3. ๐Ÿš€ Prepare the local environment

    Ensure you have jq, Azure Cli and bicep working

    jq --version
    func --version
    bicep --version
    bash --version
    az account show
  4. ๐Ÿš€ Deploying the Solution

    • Stack: Main Bicep The params required for the modules are in params.json. Modify them as needed. The helper deployment script deploy.sh will deploy the main.bicep file. This will create the following resoureces

      • Resource Group(RG)
      • VNet, Subnet & Virtual Machine
      • Virtual Machine(Ubuntu) - 2 - Defined in params.json named vmCount
        • Bootstrapped with custom libs using userData script - Installs Nginx
        • Install Azure Monitoring Agent
      • User Managed Identity - Identity attached to the VM with the following permissions,
        • Monitoring Metrics Publisher
      • Azure Load Balancer
        • Backend Pool
          • Attach VMs to the backend pool
        • Health Probe
        • Load Balancer Rule
        • Load Balancer Frontend IP
        • Load Balancer Outbound Rule

      Note - I hacked the template from another repo of mine, so you will see some unused resources(log analytics workspace/queues etc.,). You can safely ignore them, But do remember to clean up your Resource Group to avoid unnecessary costs.

    # make deploy
    sh deployment_scripts/deploy.sh

    After successfully deploying the stack, Check the Resource Groups/Deployments section for the resources.

  5. ๐Ÿ”ฌ Testing the solution

    • You can find the load balancer public IP address in the resource blade. You can also get it from the Azure Portal.

      WEB_SRV_IP="http://20.107.191.133/"
      for i in range{1..10000}; do curl ${WEB_SRV_IP}; sleep 1; done

      You should see an output like this,

       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-1</b> <b>10.0.0.5</b> on Fri May 26 22:07:28 UTC 2023 
       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-0</b> <b>10.0.0.4</b> on Fri May 26 22:07:25 UTC 2023 
       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-1</b> <b>10.0.0.5</b> on Fri May 26 22:07:28 UTC 2023 
       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-0</b> <b>10.0.0.4</b> on Fri May 26 22:07:25 UTC 2023 
       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-1</b> <b>10.0.0.5</b> on Fri May 26 22:07:28 UTC 2023 
       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-0</b> <b>10.0.0.4</b> on Fri May 26 22:07:25 UTC 2023 
       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-0</b> <b>10.0.0.4</b> on Fri May 26 22:07:25 UTC 2023 
       Hello World from miztiik-automation-vm <b>m-web-srv-web-server-lb-004-1</b> <b>10.0.0.5</b> on Fri May 26 22:07:28 UTC 2023 
      
  6. ๐Ÿ“’ Conclusion

    In this demonstration, we have shown how to bootstrap a VM using userData to install Nginx and add load balancer in the front using Bicep. We have also shown how to use User Managed Identity to access Azure resources from the VM.

  7. ๐Ÿงน CleanUp

    If you want to destroy all the resources created by the stack, Execute the below command to delete the stack, or you can delete the stack from console as well

    # Delete from resource group
    az group delete --name Miztiik_Enterprises_xxx --yes
    # Follow any on-screen prompt

    This is not an exhaustive list, please carry out other necessary steps as maybe applicable to your needs.

๐Ÿ“Œ Who is using this

This repository aims to show how to Bicep to new developers, Solution Architects & Ops Engineers in Azure.

๐Ÿ’ก Help/Suggestions or ๐Ÿ› Bugs

Thank you for your interest in contributing to our project. Whether it is a bug report, new feature, correction, or additional documentation or solutions, we greatly value feedback and contributions from our community. Start here

๐Ÿ‘‹ Buy me a coffee

ko-fi Buy me a coffee โ˜•.

๐Ÿ“š References

  1. Azure Docs: Just In Time Access

๐Ÿท๏ธ Metadata

miztiik-success-green

Level: 100