VMSS + Application Gateway + Autoscale
Run several web servers with a Virtual Machine Scale Set (VMSS), distribute traffic with Application Gateway (L7 + WAF), and configure autoscale so servers grow and shrink with demand.
🧭 What you will build in this lab
인터넷 → [공용 IP] → [Application Gateway + WAF] → [VMSS: web000000, web000001 …]Application Gateway acts like a "smart front desk" that distributes incoming requests across multiple web servers, and automatically adds more servers when they become busy.
💡 Why use the portal? In production, you typically automate this with code (Bicep/Terraform), but when learning for the first time, clicking through the portal helps you visually understand what each component is and how it connects. (A version that deploys the same architecture as code is available in
demos/vmss-appgw-ha/.)
Goal: Create the "container" that will hold all resources for this lab.
rg-lab-ha
- Region: Korea Central💡 Why start with a resource group? Every Azure resource lives inside a resource group. If you keep everything in one container, you can delete the whole container at the end of the lab and clean up costs easily (see Module 7).
✅ Check: If rg-lab-ha appears in the resource group list, you are successful.
Goal: Create the "private network" where the web servers and Application Gateway will live. Divide it into two subnets (smaller areas).
rg-lab-ha
- Name: lab-vnet
- Region: Korea Central10.0.0.0/16.
- Change the default subnet name to snet-appgw and the range to 10.0.1.0/24 (or delete it and add a new one).
- Click + Add subnet → name snet-vmss, range 10.0.2.0/24 → Add.💡 Why split the subnets in two? Application Gateway requires a dedicated subnet used only by itself. Therefore, we separate
snet-appgw(gateway only) andsnet-vmss(web servers). Microsoft recommends a/24size (about 251 IP addresses) for gateway autoscaling.
✅ Check: If you see both snet-appgw and snet-vmss in the lab-vnet > Subnets blade, you are successful.
Goal: Create multiple identical web servers at once and automatically install the nginx web server at boot time.
rg-lab-ha
- Name: lab-vmss
- Region: Korea Central
- Orchestration mode: Flexible (recommended)
- Security type: Standard
- Image: Ubuntu Server 22.04 LTS
- Size: Standard_B2s (low cost, sufficient for a demo)
- Authentication type: Password → username azureuser, enter a strong password (write it down)
- Set Scaling (instance count): 2.lab-vnet
- Subnet: select snet-vmss.
- Load balancing options: leave as None — Application Gateway will be attached separately in the next module.응답 인스턴스: $HOSTN
새로고침 해보세요.
" > /var/www/html/index.html💡 What is VMSS? Think of it as a "template mold." It stamps out identical VMs, whether you need 1 or 100. cloud-init (custom data) is an installation script that runs automatically when a VM first boots. This ensures every instance has the same web page.
✅ Check: If two instances appear as "Running" in the lab-vmss > Instances blade, you are successful.
Goal: Create an L7 gateway that receives internet requests and distributes them to the two web servers, with WAF (Web Application Firewall) enabled.
rg-lab-ha, name: lab-appgw, region: Korea Central
- Tier: WAF V2
- WAF policy: Create new (name lab-wafpolicy), mode Prevention
- Autoscaling: Yes (minimum 1)
- Virtual network: lab-vnet, subnet: snet-appgwlab-appgw-pip.vmssBackendPool.
- Leave "Add backend pool without targets" as No, set Target type: VMSS → select lab-vmss → Add.routingRule, priority 100.
- Listener: name httpListener, frontend Public, protocol HTTP, port 80.
- Backend targets tab: select backend pool vmssBackendPool → backend settings Add new (name httpSettings, port 80, HTTP) → Add.
- Add the rule.⏳ This step takes 5–10 minutes. Application Gateway is slow to create because it provisions several internal components. Time for a coffee ☕
💡 Why enable WAF? WAF (Web Application Firewall) blocks common web attacks such as SQL injection and XSS at the gateway layer. Applying the OWASP rule set (an industry-standard list of attacks) in "Prevention" mode automatically blocks suspicious requests.
✅ Check: After deployment completes, if lab-vmss is connected under lab-appgw > Backend pools > vmssBackendPool, and Backend health shows healthy (green), you are successful.
Goal: See that requests arriving at one address are distributed across multiple servers.
lab-appgw > Overview, copy the Frontend public IP address.http://<that IP> → connect.💡 Why does the name change? Application Gateway distributes (load balances) requests to different instances. Because cookie-based affinity is disabled, a different server may respond each time you refresh.
✅ Check: If the instance name alternates in the form web... as you refresh, load balancing is working.
Goal: Confirm that the service continues even if one server fails.
lab-vmss > Instances, select one instance → Stop or Delete.💡 Why does it keep working? Application Gateway's health probe checks each server every 30 seconds. It automatically removes failed servers from the distribution target list and sends traffic only to healthy servers. This is high availability.
✅ Check: If the page still responds normally after you take down one server, you are successful. (Only the healthy instance name appears.)
🔁 For the next module, return the instance count to a healthy state (2 instances). If you stopped an instance, Start it; if you deleted one, wait for automatic recovery or manually add an instance.
Goal: Create rules that automatically add servers (scale-out) and remove servers (scale-in) based on CPU utilization.
lab-vmss > Scaling blade.lab-vmss > Instances, select one instance > (Portal SSH or Run command), then:
- Enter this in VMSS > Instances > (select) > Run command > RunShellScript:
bash
sudo apt-get update -y && sudo apt-get install -y stress-ng
sudo stress-ng --cpu 0 --timeout 300s💡 Why is autoscale useful? When traffic is low, you run fewer servers to save cost; when traffic spikes, Azure automatically adds servers so the service does not slow down or fail. No one has to wake up at night to turn on servers. If average CPU stays above 70% for 5 minutes, instances are added one at a time.
✅ Check: In lab-vmss > Scaling > Run history or Instances, if the instance count increases from 2→3→… within about 5 minutes, you are successful.
When the load stops, the instance count decreases again after about 5 minutes.
⚠️ Be sure to delete the resources when the lab is complete. Application Gateway is billed while it is running.
In the portal: rg-lab-ha resource group > Delete resource group > enter the name and delete.
In the CLI:
az group delete -n rg-lab-ha --yes --no-wait
✅ Deletion status: [ ] Complete
lab-appgw > Backend health.snet-appgw, and VMSS must use snet-vmss. Do not place them in the same subnet.demos/vmss-appgw-ha/infra/main.bicep).