Today’s post will cover Scheduled Shutdown and Startup of Virtual Machines and is part of the Azure Savings series of that cover ways to save money on Azure.
Once I heard, and used ever since this analogy, that using cloud resources is similar to use electricity: the more you use, the more expensive it will be. Although, you can also save money if you apply to the cloud what you currently do for electricity
Turn off things that are not in use!
How Virtual Machines are billed?
First of, Virtual Machines are compute resources, and these are billed per hour, however, it does not mean that if you run a VM for 59 minutes you won’t be charged because you didn’t reach one hour.
In fact, Azure charges you by the number of full minutes, so to have an estimative the prices for VMs are presented per hour, or entire 60 minutes if you will.
But what does it mean by full minutes? Well, if you run your VM for 1 hour, 30 minutes and 45 seconds, the total of full minutes are 90 minutes, so Azure will do the maths and charge you accordingly.
Some math for better understanding
Let’s get the following VM size: D2 v3 (2 vCPUs, 8GB RAM) that is being presented as US$0.19/hour
By dividing 0.19 / 60 it give us the cost per minute which is 0.00316, since we have ran for 90 minutes then let’s calculate 0.19 + (0.00316 * 30 minutes)
US$0.28 for 90 minutes
If you access the Azure Calculator, you can double check the price match when you change the field in front of Hours to 1.5 that is the same as 90 minutes
How a VM price is composed?
In a cloud environment, you don’t need to think about electricity, air conditioning, a physical room to maintain the servers but that does not mean you don’t have to pay for them, because these things are embedded into VM’s price, as well as Disks, Licensing and Storage Transactions.
By going to the Azure Calculator, you can have a basic idea of how much would cost a VM
Each option could affect the final price, either by simply changing the region or by adding an additional disk. Also, this is an estimative of the price for 1 month of usage of a D2 v3 VM in Azure, US$137.44
Why should I schedule a stop / start of a VM?
To save money! Imagine a scenario where you have a VM which is used during business hours by a specific person, why would you leave the resource up & running 24×7 if isn’t required?
But prior to show how to schedule a stop / start I’d like to highlight a couple things
Stopped vs Deallocated
A VM can either be stopped or stopped (deallocated), and the difference is being charged by the compute resource or not.
In order to avoid billing for your compute resources the VM must be in a Deallocated state
Avoiding surprises
Despite the fact you are not using compute resources by deallocating the VM, there are things associated to it that you continue to billed, like the Operational System disk, for example.
Here is the cost from my Deallocated VM in a single day, about US$0.88/day (~US$26.4/month)
Dynamic Public IP vs Static Public IP
By default an Azure Virtual Machine is configured with a Dynamic Public IP, and it remains tied to the VM until it is restarted, stoppped or stopped (deallocate).
Also, a Static Public IP incurr costs when a VM is deallocated.
How to schedule shutdown / startup of a VM?
Schedule Shutdown
Go to your Virtual Machine, and under Operations look for Auto-shutdown, and click on it
Change the Enabled from Off to On, to be able to modify the options: scheduled shutdown, time zone and send notifications before auto-shutdown?
You have the ability to send a notification before auto-shutdown, by clicking on Yes and fill with one of the possibilities Webhook URL or Email address
Once you choose how the Auto-shutdown fits better for your activity, hit Save
Schedule Startup
In order to schedule the start action, you need to have an Automation Account and play with Runbooks to make it happen
At the Azure Portal, use the Search field (1) at the top of the portal and type automation, then click in Automation Accounts
In Automation Accounts, press Add
Fill the form at Add Automation Account providing Name (1), Subscription (2), Resource Group (3) and Location (4), then press Ok (5)
Once we have the Automation Account created, let’s click on it to continue the configuration
Then under Process Automation, look for Runbooks (1) and Browse gallery (2)
You can search for runbooks that would address your needs, but at this time we want to Start a VM, and it is the first option, let’s click on it Start Azure V2 VMs
Then click Import
Fill the Name (1) and press OK (2)
Back to the Runbooks, you should now see a new Runbook named StartAzureV2VM, click on it
Click Edit
And then Publish (1), and click Yes (2)
Now, let’s create a schedule by clicking Link to schedule
Click Link a schedule to your runbook
And Create a new schedule
Fill the information Name (1), Starts (2), Time zone (3), Recurrence (4), Recur every (5) and press Create (6)
Now we have the schedule set, let’s Configure parameters and run settings
Provide the following information accordingly to the Virtual Machine you want to start, and provide ResourceGroupName (1) and VMNAME (2), then press OK (3)
All set, click OK to create the schedule
At the Runbook, under Resources find Schedules and click on it, you will see there’s a schedule and showing when will be the Next Run
And that’s it!
I hope you liked it, and I’ll see you on my next post.
Photo by Sharon McCutcheon on Unsplash
Deixe um comentário