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 role-based-access-control (RBAC) to control who can create resources
- 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.
- https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Compute/VMSkusAllowed_Deny.json
- You can review the available VM sizes and cross-reference their associated costs on the pricing pages for Windows and Linux.
- 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:
- Implement policies to restrict what resources can be created:
- Implement policies to not allow certain resources to be created:
- Using the resource policy to limit the allowed locations where virtual machines can be deployed.
- Auditing resources that are incurring costs even after virtual machine deletion.
- Auditing resources to enforce the use of the Azure Hybrid Benefit.
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:
- Learn how to plan to manage costs for virtual machines.
- Learn how to monitor costs for virtual machines.
- Learn how to optimize your cloud investment with Microsoft Cost Management.
- Learn more about managing costs with cost analysis.
- Learn about how to prevent unexpected costs.
- Take the Cost Management guided learning course.
- Learn how to create Linux and Windows virtual machines.
- Take the Azure Well-Architected Framework - Cost Optimization training.