DEV Community

Abiola Omiyale
Abiola Omiyale

Posted on

Setting-Up Scale set and Load balancer On Azure

In this project ,I will show how to do the following :

  • Create a virtual machine to be syspreped and added to the Azure compute gallery.

  • How to Sysprep an image on Azure and add it to the Azure Compute gallery.

  • Create a scale set from the image in the Azure compute gallery.

  • Place a public load balancer in front of the scale set.

  • Simulate a load intensive process on the scale set to confirm the scaling policy of the scale set.

- Create A Virtual Machine :

From all resources, select create a virtual machine

Image description(IMAGE 1)

You can set up the virtual machine in any region, I will be using a Windows Server 2022 Datacenter Server Core-Gen 1 for this project. 

Image description(IMAGE 2)

Allow the Port 80- HTTP (so that the users can access the webpage over the internet), and Port 3389-(to RDP into the virtual machine)
Image description(IMAGE 3)

In the network tab, allow the application wizard to create a virtual network and subnet for the virtual machine.

There is no further configuration to be added or completed; simply click the other tabs to review and create the virtual machine. 

Image description (IMAGE 4)

Image description (IMAGE 5)

- Setting UP IIS (Internet Information Service) Web Server On The Virtual Machine

In the networking tab, we configure the RDP and map it to our IP address ( a security measure to keep access to the virtual machine restricted to the allowed IP address and from potential hackers).

In the source drop-down menu, select "My IP address." But if you have multiple IP addresses that you want to also give access to, use the (IP Address) option as shown in image 6, and input the IP addresses, each separated by a semicolon.

Image description (IMAGE 6)

Image description (IMAGE 7)

In the connect session , download the RDP file and launch the executable file, and connect to the virtual machine.

Image description (IMAGE 8)

For Windows users, you already have the RDP client pre-installed on the system.

For MAC (Apple Computers), you will need to download the Remote Desktop Client to use the RDP file executable.

For some devices that cannot run an RDP client, such as the Google Chromebook, Azure has made available the option, Azure Bastion, to log in to the virtual machine. For more information, see: https://learn.microsoft.com/en-us/azure/bastion/bastion-overview

Image description (IMAGE 9)

Image description (IMAGE 10)

When you have logged into the virtual machine, launch the server manager from the start menu. If the server does not launch automatically, from the dashboard of the server manager, click Add roles and features so we can install IIS on the server.

Image description (IMAGE 11)

Check the role-based or feature-based installation.

Image description (IMAGE 12)

Click your server name from the server pool.
Image description (IMAGE 13)

In the select roles section, tick the web server IIS and click the option to add the feature and complete the installation process.

Image description

Image description (IMAGE 14)

Go to the web root folder path, located in - windows-C:\inetpub\wwwroot\

Image description (IMAGE 15)

From Azure Portal, copy the public IP attached to the virtual machine and enter it into your browser. The default IIS webpage should be displayed.

Image description (IMAGE 16)

Replacing the default IIS webpage with my Portfolio page, http://dgns.southafricanorth.cloudapp.azure.com/

Image description (IMAGE 17)

- Sysprep an Image on Azure and add it to Azure Compute gallery

Sysprep (System Preparation) prepares a Windows client or Windows Server installation for imaging

Sysprep helps you Manage multiple PCs by creating a generic image that can be used across multiple hardware designs. For more information : https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep--system-preparation--overview?view=windows-11#sysprep-features

Since we want to spin up a scale set , we want the image to be replicated across multiple servers when users from different locations try to access the content of our web server. which is a good use case for the design for business availability and redundancy when there is a large web traffic spike to a single server infrastructure. For more information, see: https://learn.microsoft.com/en-us/azure/virtual-machines/availability

To launch the sysprep program located in the directory %windir%\system32\sysprep, tick the generalize option and also shutdown

Image description

Image description (IMAGE 18)

-Azure Compute gallery
An Azure Compute Gallery helps you build structure and organization around your Azure resources, like images and applications. For more information see: https://learn.microsoft.com/en-us/azure/virtual-machines/azure-compute-gallery

From the Azure portal, when the virtual machine shuts down, we use the capture button to create an image to be added to the Azure compute gallery. We select the option to generalise the image and create an image definition in the Azure compute gallery.

Image description (IMAGE 19)

Then click the review and create button.

Image description (IMAGE 20)

Go to the resource after it has completed the set-up. You can also locate Azure compute galleries from the Azure portal global search.

Image description (IMAGE 21)

- Create a scale set from the image in Azure compute gallery
Azure virtual machine scale sets let you create and manage a group of load-balanced VMs. The number of VM instances can automatically increase or decrease in response to demand or a defined schedule.

For more information : https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/overview#why-use-virtual-machine-scale-sets

Click the Create the VMSS button after selecting the image definition we created.

Image description (IMAGE 22)

Creating the VMSS with availability options (depending on the business design needs, it is not a must) and orchestration mode as uniform , for more information : https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-orchestration-modes

Image description (IMAGE 23)

We create the VMSS virtual machines (1 or more). In the networking tab of the virtual creation process, we will edit and disable Public IP , since we will put a load balancer in front of the VMSS.

Image description

Image description (IMAGE 24)

Image description (IMAGE 25)

We won't add a load balancer from this VMSS creation wizard. We will create it as a standalone resource and attach it to the VMSS.

Image description (IMAGE 26)

Create the virtual machine scale set, for this project:

  • initial count for the virtual machine to be one,

  • use a custom scaling policy,

  • scale out (adding more instances when these conditions are met) -CPU threshold >= 45 for a duration of five minutes and scale in policy (remove instance when CPU threshold is <= 40,

  • Maximum number of instances set to 8.

Image description (IMAGE 27)

Image description (IMAGE 28)

We tick the option to allow Azure to over provision for us in the case of critical virtual machine health and traffic spikes, when there is a delay in removing faulty virtual machines.

Image description (IMAGE 29)

Click the review and create button.

Image description (IMAGE 30)

The created virtual machine has no public IP attached to it, and the instance count is one.

Image description (IMAGE 31)

In the monitoring section of the VMSS, the CPU average is under 20%.

Image description (IMAGE 32)

- Place a public load balancer in front of the scale set

Create the load balancer with the following parameters: since we are attaching the load balancer to a VMSS, we can't use a Basic SKU load balancer, and since we want users to access the webpage of the VMSS, we create the load balancer as a Public , Tier Regional.

Image description (IMAGE 33)

Frontend IP configuration , where we set up the public IP address for the backend (VMSS).

Image description (IMAGE 34)

Backend pool, select the virtual network where the VMSS is located, with backend pool configuration (NIC).

Image description (IMAGE 35)

Because in my environment , I have two virtual machines in the same VNET. It shows all the available virtual machines in the VNET that can be added to the backend pool.

Image description (IMAGE 36)

Image description (IMAGE 37)

In the inbound rules section, we add the load balancing rules, using the configurations highlighted below :

Image description (IMAGE 38)

Image description (IMAGE 39)

Image description (IMAGE 40)

Image description (IMAGE 41)

We won't be adding outbound rules to the load balancer; we'll review and create them.

Image description (IMAGE 42)

We confirm the frontendIP configuration that will be attached to the VMSS is available (23.164.39.101).
Image description (IMAGE 43)

Also confirm from the Azure portal for the Virtual Machine Scale Set that the frontend-IP configuration from the load balancer has been attached to the Virtual Machine Scale Set (enlarged(23.3164.39.101)).

Image description (IMAGE 44)

Let's see if the IP still redirects to our page, and sure enough, it still loads my portfolio page. 
Image description (IMAGE 45)

Under the monitoring tab of the VMSS, the CPU average should be stable since the workload the webserver is receiving is stable.
Image description (IMAGE 46)

Also confirming from the instance itself, the CPU average is also stable
Image description (IMAGE 47)

Image description (IMAGE 48)

- Simulate a load intensive process on the scale set to confirm the scaling policy of the scale set.

In this section, we will attempt to simulate a CPU intensive workload on the webserver, to confirm if the scale set , scale-out (adding more servers to cope with the increased workload when the CPU threshold is exceeded), and scale-in (removing extra servers when the CPU intensive process reduces and within the threshold set for CPU average) are correct.

We will use the Azure serial console, which will give us access to the guest OS operation of the webserver. We provisioned a Windows server. For more information, see: https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/serial-console-overview

When the prompts appear in the command prompt after launching the serial console, do the following :

  • in the SAC prompt,input : cmd

  • in the channel prompt, input : ch -si 1

Image description (IMAGE 49)

Input your username, then press enter for domain (the server is not domain joined), and your password.
Image description (IMAGE 50)

Then, in the windows prompts to switch to PowerShell , type PowerShell. The script to help simulate is a PowerShell script.
Image description (IMAGE 51)

Copy and paste the PowerShell script into the prompt and press enter when it prompts for the enter key.
The PowerShell script is in the code snippet below. Sourced from this site : https://www.robvit.com/windows_server/generate-cpu-load-with-powershell/

*NOTE: * Please don't use this script in a production or critical server environment. This a test environment and project, and the servers will be deleted after this exercise.

Image description (IMAGE 52)


$NumberOfLogicalProcessors = Get-WmiObject win32_processor | Select-Object -ExpandProperty NumberOfLogicalProcessors

ForEach ($core in 1..$NumberOfLogicalProcessors){ 

start-job -ScriptBlock{

    $result = 1;
    foreach ($loopnumber in 1..2147483647){
        $result=1;

        foreach ($loopnumber1 in 1..2147483647){
        $result=1;

            foreach($number in 1..2147483647){
                $result = $result * $number
            }
        }

            $result
        }
    }
}

Read-Host "Press any key to exit..."
Stop-Job * 
Enter fullscreen mode Exit fullscreen mode

After some minutes of rechecking the CPU average metrics of the virtual machine, there is a sudden spike in the CPU usage.
Image description (IMAGE 53)

Checking the instance count of the virtual machines, there is a scale-out ( more instances are being added).
Image description (IMAGE 54)

From the monitoring tab of the virtual machine scale set, we can see the spike in the CPU average (Note : this was taken after the CPU average had gone back to the normal level, to show the peak and low periods).

Image description (IMAGE 55)

The instance count confirms that the total number of virtual machines has been added and deleted. In the scaling rule, the instance maximum limit was pegged at 8 instances, as shown in image 57

Image description (IMAGE 56)

Image description (IMAGE 57)

The instance been automatically deleted, when scale-in rule kicked in.
Image description (IMAGE 58)

Another look at the CPU average when it has gone back to its normal state after the spike.
Image description (IMAGE 59)

And we are back to one virtual machine (named enlargedscale_3 in my environment, I started with enlargedscale_1).
Image description (IMAGE 60)

The next projects will be working on the Arm template to spin up virtual machines and different resources.

Links to other Azure projects :
Setting-Up A Basic Azure Load Balancer & Availability Sets https://dev.to/cli_tayo/setting-up-a-basic-azure-load-balancer-availability-sets-14m1

Adding A Virtual Machine To An Existing Availability sets On Azure
https://dev.to/cli_tayo/adding-a-virtual-machine-to-an-existing-availability-sets-on-azure-ahh

Top comments (0)