VM Scale Sets for auto scaling in Azure - Mini Project: Build & Apply
Create an Azure VM Scale Set resource named myScaleSet in the eastus region. Use the VM size Standard_DS1_v2 and the image UbuntuLTS. Define the scale set with a capacity of 2 instances.
Use the azurerm_linux_virtual_machine_scale_set resource with the exact name myScaleSet. Set location to eastus, sku to Standard_DS1_v2, and instances to 2. Use the Ubuntu 18.04 LTS image from Canonical.
Create a variable called autoscale_min and set it to 2. Create another variable called autoscale_max and set it to 5. These will define the minimum and maximum number of VM instances for autoscaling.
Use Terraform variable blocks named exactly autoscale_min and autoscale_max with default values 2 and 5 respectively.
Create an autoscale setting resource named myAutoscaleSetting linked to the VM Scale Set myScaleSet. Add a rule to increase instances by 1 when average CPU percentage is above 70% for 5 minutes. Add another rule to decrease instances by 1 when average CPU percentage is below 30% for 5 minutes.
Use the azurerm_monitor_autoscale_setting resource named myAutoscaleSetting. Link it to the VM Scale Set using target_resource_id. Add two rules: one to increase instances when CPU > 70%, and one to decrease when CPU < 30%. Use 5 minutes cooldowns.
In the autoscale setting myAutoscaleSetting, ensure the default capacity is set to 2. Set the cooldown period for both scale actions to PT5M (5 minutes). Confirm the autoscale setting is fully configured with these values.
Check that the capacity block has default = "2". Both scale_action blocks should have cooldown = "PT5M".
Practice
Solution
Step 1: Understand VM Scale Sets function
VM Scale Sets allow running multiple VMs that can increase or decrease automatically.Step 2: Identify the main benefit
This automatic adjustment helps handle changes in workload efficiently.Final Answer:
To automatically adjust the number of virtual machines based on demand -> Option CQuick Check:
Auto scaling = Adjust VM count [OK]
- Confusing VM Scale Sets with storage services
- Thinking it manages user permissions
- Assuming it creates only one VM
Solution
Step 1: Identify correct metric and operator
The autoscale rule should trigger when CPU usage is greater than 70%, so metric 'Percentage CPU' and operator 'GreaterThan' are correct.Step 2: Confirm action to add instances
The rule must add instances when the condition is met, not decrease or use wrong metrics.Final Answer:
Set a rule to add instances when CPU > 70% using metric 'Percentage CPU' and operator 'GreaterThan' with threshold 70 -> Option AQuick Check:
CPU > 70% triggers add instances [OK]
- Using 'LessThan' instead of 'GreaterThan'
- Confusing CPU with memory metrics
- Setting decrease action instead of add
{
"metricTrigger": {
"metricName": "Percentage CPU",
"operator": "GreaterThan",
"threshold": 80
},
"scaleAction": {
"direction": "Increase",
"value": "2"
}
}What happens when CPU usage goes above 80%?
Solution
Step 1: Analyze metric trigger
The rule triggers when CPU usage is greater than 80%.Step 2: Analyze scale action
The action is to increase the VM count by 2 instances.Final Answer:
The VM Scale Set increases by 2 instances -> Option BQuick Check:
CPU > 80% triggers increase by 2 [OK]
- Confusing increase with decrease
- Ignoring the value number
- Assuming default increase of 1
Solution
Step 1: Check metric name correctness
If the metric name is wrong, the rule never triggers because it can't read CPU usage.Step 2: Verify other options
Direction 'Decrease' would scale down, threshold 10 is too low but would still trigger, and initial instances are usually at least one.Final Answer:
The metric name is misspelled or incorrect -> Option AQuick Check:
Wrong metric name blocks scaling [OK]
- Setting wrong scale direction
- Ignoring metric name spelling
- Assuming zero initial instances
Solution
Step 1: Confirm instance limits
The requirement is minimum 3 and maximum 10 instances, so only Set minimum 3, maximum 10 instances; add 2 when CPU > 75%; remove 1 when CPU < 30% matches this.Step 2: Check autoscale rules
Set minimum 3, maximum 10 instances; add 2 when CPU > 75%; remove 1 when CPU < 30% adds 2 instances when CPU > 75% and removes 1 when CPU < 30%, exactly as required.Final Answer:
Set minimum 3, maximum 10 instances; add 2 when CPU > 75%; remove 1 when CPU < 30% -> Option DQuick Check:
Limits and rules match requirements [OK]
- Mixing up CPU thresholds for add/remove
- Setting wrong min or max instance counts
- Reversing scale directions
Ready to prove it?
Pass the test and this pattern moves unknown
