Breyta

Deila með


Best practices for virtual machine cost optimization

This article describes the best practices for managing costs for virtual machines.

If you'd like to see how the billing model works for virtual machines and how to plan for costs ahead of resource deployment, see Plan to manage costs. If you'd like to learn how to monitor costs for virtual machines, see Monitor costs for virtual machines.

In this article, you'll learn:

  • Best practices for managing and reducing costs for virtual machines
  • How to use Azure policies to manage and reduce costs

Best practices to manage and reduce costs for virtual machines

The following are some best practices you can use to reduce the cost of your virtual machines:

  • Use the virtual machines selector to identify the best VMs for your needs
    • For development and test environments:
      • Use B-Series virtual machines
        • Use at least B2 for Windows machines
      • Use HDDs instead of SSDs when you can
      • Use locally redundant storage (LRS) accounts instead of geo- or zone-redundant storage accounts
      • Use Logic Apps or Azure Automation to implement an automatic start and stop schedule for your VMs
    • For production environments:
      • Use the dedicated Standard pricing tier or higher
      • Use a Premium SSD v2 disk and programmatically adjust its performance to account for either higher or lower demand based on your workload patterns
      • For other disk types, size your disks to achieve your desired performance without the need for over-provisioning. Account for fluctuating workload patterns, and minimizing unused provisioned capacity
  • Use role-based-access-control (RBAC) to control who can create resources
  • Use Azure Spot virtual machines where you can
  • For Windows virtual machines, consider Azure Hybrid Benefit for Windows Server to save cost on licensing
  • Use cost alerts to monitor usage and spending
  • Minimize idle instances by configuring autoscaling
  • Configure Azure Bastion for operational access

Use policies to help manage and reduce costs for virtual machines

You can use Azure Policy to help govern and optimize the costs of your resources.

There are built-in policies for virtual machines and networking services that can help with cost savings:

  • Allowed virtual machine SKUs - This policy enables you to specify a set of virtual machine size SKUs that your organization can deploy. You could use this policy to restrict any virtual machine sizes that exceed your desired budget. This policy would require updates to maintain as new virtual machine SKUs are added.
  • Network interfaces should not have public IPs - This policy restricts the creation of public IP addresses, except in cases where they are explicitly allowed. Restricting unnecessary exposure to the internet can help reduce bandwidth and virtual network data costs.

You can also make custom policies using Azure Policy. Some examples include:

Next steps

In this article, you learned the best practices for managing and reducing costs for virtual machines and how to use Azure policies to manage and reduce costs.

For more information on virtual machine cost optimization, see the following articles: