Skip to main content

Command Palette

Search for a command to run...

Beginner Guide: Deploying an Azure VM Scale Set (VMSS) with Apache2

In this guide, you will learn how to: Create an Azure Virtual Machine Scale Set (VMSS) Configure a Virtual Network and Load Balancer Automatically install Apache2 on all VM instances Enable HTTP traffic using a Network Security Group (NSG) Test load balancing across multiple virtual machines By the end of this setup, you will have a scalable web server environment running on Azure.

Updated
5 min readView as Markdown
Beginner Guide: Deploying an Azure VM Scale Set (VMSS) with Apache2
A
Tech enthusiast currently transitioning into cloud computing and exploring modern technologies.

Step 1: Create a Resource Group

  1. Search for Resource Groups in the Azure Portal.
  1. Click Create.

Under the Basics tab:

  • Enter a Resource Group name

  • Select a Region

Click:

  • Review + Create

  • Create

Step 2: Create a Virtual Network (VNet)

  1. Search for Virtual Network.
  1. Click Create.

Under the Basics tab:

  • Select your Resource Group

  • Enter a VNet name

Under the IP Addresses or Address Space section:

  1. Click the Subnet edit icon

  2. Edit the subnet name

  3. Click Save

Then click:

  • Review + Create

  • Create

Step 3: Create a Load Balancer

The Load Balancer distributes incoming traffic across multiple VM instances.

  1. Search for Load Balancer
  1. Click Create

  2. Select Standard Load Balancer

Under the Basics tab:

  • Select your Resource Group

  • Enter a Load Balancer name

  • Select your Region

Configure:

  • SKU: Standard

  • Type: Public

  • Tier: Regional

Click Next: Frontend IP Configuration

Configure Frontend IP

  1. Click Add a frontend IP configuration
  1. Enter a name

  2. Under Public IP, click Create new

  3. Enter a Public IP name

  4. Click Save

Configure Backend Pool

  1. Go to Backend Pools

  2. Click Add

  1. Enter a Backend Pool name

  2. Select your Virtual Network

  3. Click Save


Configure Load Balancing Rule

  1. Go to Inbound Rules
  1. Click Add Load Balancing Rule

Configure:

  • Rule name

  • Frontend IP address

  • Backend Pool

  • Protocol: TCP

  • Port: 80

  • Backend Port: 80


Configure Health Probe

Under Health Probe:

  1. Click Create New

  2. Enter a name

  3. Configure:

    • Protocol

    • Port

    • Interval

Click Save

Finally, click:

  • Review + Create

  • Create

Step 4: Create the Virtual Machine Scale Set (VMSS)

  1. Search for Virtual Machine Scale Set
  1. Click Create

Basics Tab

Configure the following:

  • Resource Group

  • VMSS name

  • Region

  • Availability Zone

  • Image: Ubuntu Server

  • VM Size

Under Orchestration Mode, select:

  • Flexible

Flexible orchestration allows Azure to scale using different VM sizes based on workload demand.

Enter:

  • Username

  • Password


Configure Autoscaling

If Autoscaling is unavailable, the Microsoft.Insights resource provider may not be registered.

Register Microsoft.Insights

  1. Go to the Azure Portal

  2. Search for Subscriptions

  3. Select your subscription

  4. Click Resource Providers

  5. Search for Microsoft.Insights

  6. Click the 3-dot menu

  7. Click Register

  8. Wait a few minutes for registration to complete

  9. Refresh the VMSS page


Configure Scaling Rules

Under Scaling Mode:

  1. Select Autoscaling

  2. Click the Configure default condition edit icon

Configure:

  • Default instance count

  • Minimum instance count

  • Maximum instance count

  • Scale-out CPU threshold

  • Scale-in CPU threshold

  • Increase instance count by

  • Decrease instance count by

  • Query duration

Click Save


Configure Networking

Under the Networking tab:

  • Select your Virtual Network

  • Select your Subnet

Under Load Balancing:

  • Select the previously created Load Balancer

  • Select the Backend Pool


Disable Boot Diagnostics

Under the Management tab:

  • Set Boot Diagnostics to Disable

Add Apache2 Installation Script

Under the Advanced tab, paste the following script into Custom Data:

#!/bin/bash
sudo apt-get update -y
sudo apt-get install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2

HOSTNAME=$(hostname)

cat <<EOF | sudo tee /var/www/html/index.html
<html>
<head>
<title>Azure VMSS</title>
</head>
<body>
<h1>Hello from $HOSTNAME</h1>
<p>Azure VMSS Instance</p>
</body>
</html>
EOF
sudo systemctl restart apache2

This script automatically:

  • Installs Apache2

  • Starts the Apache web server

  • Creates a custom webpage displaying the VM hostname

Click:

  • Review + Create

  • Create

After deployment completes, click Go to Resource.

View VM Instances

To view the created virtual machines:

  • Open the VMSS resource

  • Click Instances from the left menu

You will see all VM instances created within the scale set.

Get the Load Balancer Public IP

  1. Open the created Load Balancer

  2. Under Settings, click Frontend IP Configuration

  3. Copy the Public IP Address

Example:

http://20.xxx.xxx.xxx

Paste the IP address into your browser.

Step 5: Configure NSG to Allow HTTP Traffic

Your website may still be inaccessible because inbound HTTP traffic is blocked by default.

Allow Port 80

  1. Search for Network Security Group
  1. Open the NSG attached to the VMSS

Go to:

  • Inbound Security Rules

  • Click Add

Configure:

  • Source: Any

  • Source Port Range: *

  • Service: HTTP

  • Action: Allow

  • Name: AllowPort80

Click Add

Test the Deployment

Open the Load Balancer Public IP in your browser:

http://<public-ip>

You should see:

Hello from vm-name
Azure VMSS Instance

Refresh the page multiple times.

You will notice the VM hostname changes, confirming that the Load Balancer is distributing traffic across multiple VM instances.

Conclusion

You have successfully:

  • Created an Azure VM Scale Set (VMSS)

  • Configured Autoscaling

  • Installed Apache2 automatically using Custom Data

  • Configured a Public Load Balancer

  • Allowed HTTP traffic through an NSG

  • Verified traffic distribution across VM instances

You now have a basic scalable web server infrastructure running on Azure.

More from this blog

dml.ops

23 posts