AZ-900-EN

【AZ-900】3 Effective Ways to Reduce Azure Virtual Machine Costs

【AZ-900】3 Effective Ways to Reduce Azure Virtual Machine Costs

Hi, I’m Makoto, a freelance engineer.

In this article, I explained what costs are associated with virtual machines.

【AZ-900】Understanding Azure VM Costs_ A Breakdown of Cost Factors
【AZ-900】Understanding Azure VM Costs: A Breakdown of Cost FactorsHi, I'm Makoto, a freelance engineer. In this article, I'll expla...

While it’s convenient to create and delete them easily,

I want to use them as cheaply as possible…

Everyone thinks like that, right?
So in this article I’ll explain how to reduce the cost of Azure virtual machines.

I’ll not only introduce you to Azure’s typical discount options, but I’ll also give you some tips on how to save money, so please read to the end.

Let’s get started!

How to Use Virtual Machines Cheaply

Azure Spot Virtual Machines

When I first started learning Azure, I tried to choose the cheapest and least powerful sizes to minimize costs. But with Windows Server, if you only have 1 core, it’s so slow that it’s inefficient for learning.

It’s too slow to be usable…

This is where Azure Spot Virtual Machines come in. In AWS they are called Spot Instances.

With Spot VMs, you can get significant discounts by using Azure’s idle resources, which are excess resources that are not being used.

To use a Spot VM, simply check the “Run with Azure Spot discount” box on the virtual machine creation screen.

Run with Azure Spot discount

In the example screen, the price for the “DS1_v2” size is $0.01646 per hour.

The unit price for Spot VMs fluctuates. The size you choose today may not be the same price or the cheapest tomorrow.

I often show all sizes, then ungroup them and sort by cost in ascending order, choosing a size with about 2 cores and 8GB of memory. You can see that all sizes are discounted by about 70% to 90%.

Select a VM size

There are two main points to be aware of when using Spot VMs:

  • The VM may be stopped
  • You may hit quota limits

The first point is that there’s a possibility that Azure will forcibly stop your VM. Of course, SLAs don’t apply.

Spot VMs are based on using excess resources, but if resources are needed elsewhere, they will be stopped without question. More specifically, the behavior depends on the “eviction policy” and you can choose between “stop/deallocate” or “delete”.

Available capacity varies by size, region, time of day, and other factors. If you are getting stopped/deleted, it might be a good idea to try changing regions.

How often is there a possibility of being stopped?

In my experience, I’ve been forced to stop a few times, but not very often. When I tried to immediately start a stopped virtual machine, it was quickly stopped again.

You will need to use it for purposes where it doesn’t matter if it stops at any time, but I don’t think it will be much of a problem if you are using it to learn Azure, so please try it out.

The second point is that you might not be able to create a Spot VM due to reaching the CPU core limit (quota).

This is not limited to Spot VMs, but in Azure, there are limits called “quotas” set for each subscription and service.

The default number of cores for both regular virtual machines and Spot VMs is 20 but varies by subscription type and series. Quotas are set separately for regular virtual machines and Spot VMs.

In my subscription, the limit for Spot VMs was set to “3”. If you can’t select because you don’t have enough quota, you can request an increase by clicking Request Quota.

Request quota

Key Points:

Spot VMs are suitable for temporary usage scenarios and can offer significant discounts.

Azure Reserved Virtual Machine Instances (RIs)

Azure Reserved Virtual Machine Instances is a system that allows you to get discounts by reserving virtual machine usage for 1 or 3 years. This is similar to Reserved Instances in AWS.

In practice, you can purchase from the Reservations menu, and there are services other than virtual machines that can be reserved.

Purchase reservations

It’s often explained as requiring an “upfront payment”, but currently you can also choose monthly payments (the contract period is 1 or 3 years).

Select the product you want to purchase

It’s easy to misunderstand, but selecting and purchasing a virtual machine from the Reservations menu does not create an instance.

It’s more like buying a discount coupon or ticket, and when a virtual machine of the specified region and size is created, it is automatically applied.

Be aware that the reservation discount will not be applied if the combination of the specified region and specified size is different. Be especially careful with the size. It’s easy to confuse “D4” and “DS4”, for example, so be careful when making reservations. It seems that exchanges and refunds are possible.

Another point to note is that only the virtual machine is discounted, not the disk fees. There’s a separate reservation for managed disks, so if you purchase those as well, you can get a discount (currently only Premium SSD qualifies).

Purchase reservations - Managed Disks

Key Points:

If you’re planning long-term use, you can get significant discounts by purchasing reservations.

Azure Hybrid Benefit (AHB)

Azure Hybrid Benefit is a program that allows you to receive discounts on license usage fees by bringing in existing on-premises licenses.

Currently, the following licenses are eligible. Enterprise Linux operating systems are also eligible.

  • Windows Server
  • SQL Server
  • Red Hat Enterprise Linux (RHEL)
  • SUSE Linux Enterprise Server (SLES)

To take advantage of the hybrid operating system, check the box on the virtual machine creation screen. It appears that you can check the box and create without a license, but this would be a license violation, so don’t do it.

Licensing

Key Points:

If you bring in existing licenses, you can get discounts on license fees.

Bonus Section

So far, we’ve looked at ways to reduce virtual machine usage fees, but as a tip, I’d like to share some techniques for avoiding unnecessary costs.

Set Up Auto-Shutdown

I think this is common for Azure beginners, but have you ever forgotten to stop a virtual machine you created, left it running, and unintentionally incurred charges? I’ve done this many times.

You can automatically shut down the virtual machine at a specified time to stop billing.

Auto-shutdown

You can also enable auto-shutdown when creating a virtual machine.
These kinds of mistakes are not only about money, but also cause significant mental damage, so if you’re learning, I recommend setting it to your sleep time.

Use small disk

As introduced in this article, for Windows, you can reduce the OS disk capacity (127GB → 30GB) by using the small disk OS image, which can save costs.

【AZ-900】Summary of Virtual Machine Components
【AZ-900】Summary of Virtual Machine ComponentsHi, I'm Makoto, a freelance engineer. Virtual machines are a basi...

View all images and look for one with [smalldisk] at the beginning in the WindowsServer dropdown.

Select a image (smalldisk) Be careful not to select the wrong one, because even with [smalldisk] there are “Containers” and “Server Core” mixed in. The dropdown is a bit tricky to select…

Register Budget Alerts

By registering for Budget Alerts, you can receive an email when the billing amount reaches the set amount.

You may want to set this up first to avoid high charges due to forgetting to delete created resources or stop servers.

For setup instructions, see this article.

【AZ-900】Essential Setup_ How to Prevent Overspending with Budget Alerts in Azure
【AZ-900】Essential Setup: How to Prevent Overspending with Budget Alerts in AzureHi, I'm Makoto, a freelance engineer. When I first started to lea...

Summary

We’ve introduced methods for reducing the cost of Azure virtual machines, including three discount options and techniques for avoiding unnecessary costs.

The AZ-900 exam may ask about the three discount options introduced in the first half, so make sure you understand the usage scenarios and characteristics of each.

The bonus techniques will also be useful for personal study. Please use them to avoid unnecessary expenses!

See you next time!

View Azure Courses