Create a Standard Load Balancer with Azure CLI

45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Your company has an application that is overloaded. Whenever there’s a spike in traffic, the application is unresponsive. You must implement a load balancer to save the application from crashing and improve response times.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create Virtual Machines
  1. Log in to the Azure Portal and open a Bash prompt in Cloud Shell.
  2. Create a network interface for your VMs.
  3. Create two VMs to add to the load balancing pool.
Create a Load Balancer
  1. Create a load balancer and load balancing rules for port 80.
  2. Test the connectivity to your load balancer by accessing the public IP address from a new browser tab.

Additional Resources

You've been provided with one VM with this hands-on lab, which is the VM that hosts your application now. You will create a network interface for the two new VMs you are to create that will be load balanced. You will then create the VMs with the appropriate network interfaces attached. Use the following cloud-init script to install the packages during the deployment:

#cloud-config
package_upgrade: true
packages:
  - nginx
  - nodejs
  - npm
write_files:
  - owner: www-data:www-data
  - path: /etc/nginx/sites-available/default
    content: |
      server {
        listen 80;
        location / {
          proxy_pass http://localhost:3000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection keep-alive;
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
        }
      }
  - owner: azureuser:azureuser
  - path: /home/azureuser/myapp/index.js
    content: |
      var express = require('express')
      var app = express()
      var os = require('os');
      app.get('/', function (req, res) {
        res.send('Hello World from host ' + os.hostname() + '!')
      })
      app.listen(3000, function () {
        console.log('Hello world app listening on port 3000!')
      })
runcmd:
  - service nginx restart
  - cd "/home/azureuser/myapp"
  - npm init
  - npm install express -y
  - nodejs index.js

Once you've deployed the VMs, create a standard load balancer with a frontend and backend pool. The load balancer should also have rules for port 80 going to the frontend pool.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?