Auto-scaling/resizing of Azure Virtual Machines without PowerShell
If you are interested in shutting down Azure VMs on a schedule, learn more here. If shutting down a VM during non-busy hours is impractical, consider scaling it down in power.
In this tutorial, we are going to learn how to do scaling/resizing of Azure (up or down) cloud-based Microsoft Azure Virtual Machines on a schedule. The process takes about 1-2 minutes and is easily replicable to any and all VMs in your Azure subscription in just a few minutes more. It works for Windows and Linux VMs and does not rely on somewhat complex and hard to maintain PowerShell scripts or Azure Automation runbooks. Also, if any errors occur during execution of scale commands, you will get an immediate notification.
Scheduling scaling of your VMs allows you to save money on Azure costs. A scaled-down VM incurs lowered Azure charges This can be beneficial for DEV/QA and other non-production environments, CI/build servers, or for production environments where optimal access to VMs is required only during specific times. Consider an example: a CI/SourceCode build server must be very powerful during the day time to assist the development team with continuous builds after frequent check ins. However, during the night hours, it can be scaled down in size to support occasional check ins from a few developers who are working late.
Step 1 – Get a Netreo Account
You will need a Netreo account. If you have not yet registered, do so here. Netreo is a sophisticated monitoring and automation software-as-a-service for Azure. By using Netreo, you’ll have access to a ton of useful performance metrics, logs, alerts, integrations, and other automation features. While during the 2-week trial period everything in Netreo is free, after the trial expires, automated VM Resizing will only be available for users of Netreo’s Ultimate plan. Many companies easily justify the relatively inexpensive cost of Netreo by configuring it to power-down or scale-down their unused VMs.
Technical considerations to note: when a VM is resized, it is rebooted. VM resizing is not recommended for stand-alone servers that need to remain up 24/7. It is recommended that such servers be a part of multi-server Availability Sets, so that reboots in one server do not cause the whole availability set to be down.
Resizing a VM does not cause any change to OS or underlying data. It is simply rebooted with more or less power allocated to it by Azure platform.
Step 2 – Connect Netreo to your Azure Subscription
Ensure that your Azure Virtual Machines have been added to Netreo account. Simplest way to do so is to run through the Netreo Setup Wizard. It takes a few minutes, and it is very intuitive and straightforward.
Step 3 – Define Resize Up and Resize Down actions to execute at specific times
After Wizard completes, edit the monitoring definition of a particular Azure VM and on the Actions tab and define two actions; one to resize UP and one to resize DOWN a VM at specific times. In detail:
- Bring up an Edit dialog for a specific Azure VM from Netreo dashboard
- On the Actions tab, add a new action. This will be the action to Resize DOWN the VM at a specific time
- Specify Name and Severity of the action
- Ensure that Action execution is based on a Schedule instead of an Expression
- Define a Start time of the action by creating a new Schedule entry of type Action Execution (keep in mind that the start time is defined in UTC). Schedule setup is quite flexible and has many more scheduling options than Azure’s native Scheduler.
- Execution target should remain as “Self”
- Execution Command should be “AzureVmInstanceResize”. Choose the target size of the VM
- Keep in mind that Netreo will also send out alerts in case of either success or failure of action execution
- Save and Done.
- Now rinse and repeat this process to create a similar Resize UP action. Use “AzureVmInstanceResize” command with a different target size and a different time schedule.
- Since the Schedule setup is quite flexible, you are able to create any number of Resize UP and DOWN actions under a single resource to accommodate different schedules for weekdays and weekends, specific weeks of the month, etc.
Step 4 (Optional) – Automate other Virtual Machines quickly
Configuring other VMs to scale on the same schedule is a fairly trivial task in Netreo.