PowerShell, Office 365, Azure and automation
Azure Cost Savings

Azure Cost Savings

Azure Cloud is great, but sometimes looks a bit pricy and people start thinking – Why it is like that? Does it suits me? Can I make it cheaper?

Please find some recommendations what can you do to reduce costs. I spent quite a while collecting all this options. Hope that helps you to save some money you may want to use for something else.

Azure free services

If you just playing or start practicing with Azure you may find that Azure free resources good enough for your aims.

When you just register, you can get 200$ to spend for the first month as a present from Microsoft. After the first month there will be free services for 12 month. It is not much, but enough for some checks, POC and building a playground.

This is not a full list of those:

  • Windows Virtual Machines (B1S Standard tier – 750 hours)
  • Linux Virtual Machines (B1S Standard tier – 750 hours)
  • Blob Storage (5 GB)
  • File Storage (5GB)
  • Standard Load Balancer (750 hours, 15 GB data processing, 5 rules)
  • Archive Storage (10 GB LRS/GRS write and retrieval plus 100 reads)
  • Azure Database for MySQL (new)
  • Media Services—Encoding (new)
  • Key Vault (new)
  • And a lot of others

This is the list of that Azure always free resources:oh_yeah_its_free

  • Azure AD (free tier)
  • Azure Cosmos DB (400 request units per second)
  • Azure Functions (1,000,000 requests per month)
  • Azure DevOps (up to 5 users with unlimited private Git repos)
  • Virtual Network (50 virtual networks)
  • SQL Server 2019 Developer Edition

This list doesn’t update often, but it is good to check of you just started your Azure journey. The latest updates of the list can be found with the link.

Automate provisioning for Active-Passive

If your software doesn’t work Active-Active for HA and redundancy, you can write code to automate provisioning of your infrastructure in another zone or region in case of any issues with the Primary (Active) one. You need to think about monitoring software and load balancer with health checks (I think Traffic Manager can do that).

In case of failure of your primary app stack, monitoring software could trigger a provisioning for another app stack by webhook with Azure DevOps. Provisioning is pretty quick and usually takes minutes to deliver and Azure DevOps can also help to deploy the latest stable version of your app.

You might not have a 100% working environment all the time, but you also don’t need to pay for any infrastructure for your Passive resources.

Azure VM and disk performance

As you might know a VM performance is limited by VM size. That helps you to limit the price you pay with performance you can achieve. You can find the details for each VM size here. One of a limits for VM performance is IO throughput, not only CPU speed and RAM size. You can calculate the IOPS per disk attached to a VM and if it is more than VM can handle – it will be capped. Do benchmarks and don’t pay more for disks speed if VM size is you limit.

One more option here is to use cache for disks. There are two types of cache: Read and Read-Write. First is very helpful when you get data for reports\analysis. It really helps to improve user experience. The second one suits for workloads that do a balance of read and write operations like file server. Detailed explanation for how to design and benchmark IOPS for our app can be found here.

Azure Disk storage reservation

One more way to optimize your Azure costs is to save on Azure Disk Storage usage with reserved capacity. Currently, Azure Disk Storage reservations are available only for select Azure premium SSD SKUs. The reservation discount is applied automatically to the matching disks in the selected reservation scope. Because of this automatic application, you don’t need to assign a reservation to a managed disk to get the discounts. Discounts are applied hourly depending on the disk usage. Unused reserved capacity doesn’t carry over. Azure Disk Storage reservation discounts don’t apply to unmanaged disks, ultra disks, or page blob consumption. If you consider this one interesting you can find more information here.

Azure RI (Reserved Instances)

Most of the Azure users heard about reservations that could be made on virtual machines. That feature is available for 1 or 3 years. It require you to pay ahead and get a discount. Makes sense if you provision production workload to Azure that will work 24×7 so you get a reasonable price for what you use. You can get up to 72% discount with that and up to 8o% if it get combined with Azure Hybrid Benefit. Azure gives you some options and flexibility for use of prepaid Reserved Instances. If you want to find more or get the latest information about that, please go here.

Interestingly, you can reserve not only VM’s, but some other instances too. For example:

save with Azure reserved instances and Azure Hybrid Benefit

 
  • SUSE or Red Hat Linux software plans
  • Azure Cache for Redis
  • Azure Database for PostgreSQL, MySQL or MariaDB
  • Azure Data Factory data flows
  • Azure Storage reserved capacity

Yes, there are limitations with what you can reserve, but with good planning, proper attitude and attention to details you can safe quite something. Most reservations, are applied on an hourly basis. Consider reservation purchases based on your consistent base usage. You can find out which reservation to purchase by regularly analysing your usage data or by using reservation recommendations. Recommendations are available in:

  • Azure Advisor (VMs only)
  • Reservation purchase experience in the Azure portal
  • Cost Management Power BI app
  • APIs

Latest updates about reservations can be found here.

If you are ready to make a commitment and buy a reservation – check this link.

Azure Hybrid Benefit

This one is a really simple option: if you already have Software Assurance-enabled Windows Server or SQL Server –  you can use that license in Azure and save on renting a license.

The same feature works with RedHat and SUSE Linux.

The detailed explanation and savings calculator can be found here

Azure VM automated Start\Stop

There is a feature to allow you start and stop your VM’s based on different parameters (user defined schedules, tags). Old technology (v1) is going away and should be deprecated in May 2022. The new technology (v2) is already here and brings us new features, like “Autostop VMs based on low CPU usage“.

The overview, latest updates and how-to’s can be found here

Azure unused\not required resources

It is a good idea to identify what can be safely removed from your subscriptions, but not always easy to find. Moreover, not all the resources not get deleted together. You can always use Azure Advisor and Security Center. Those tools are very helpful, can show a lot of good advice and keep improving. Unfortunately, they can cover everything. Please see some scripts to be used for disks and network cards look up.

Unattached Azure managed disk

 Connect-Azaccount
 Get-Azsubscription
 Select-Azsubscrciption -Subscription "Subscription Name"
 # Set deleteUnattachedDisks=1 if you want to delete unattached Managed Disks
 # Set deleteUnattachedDisks=0 if you want to see the Id of the unattached Managed Disks
 $deleteUnattachedDisks=0
 $managedDisks = Get-AzDisk
 foreach ($md in $managedDisks) {
     # ManagedBy property stores the Id of the VM to which Managed Disk is attached to
     # If ManagedBy property is $null then it means that the Managed Disk is not attached to a VM
     if($md.ManagedBy -eq $null){
         if($deleteUnattachedDisks -eq 1){
            Write-Host "Deleting unattached Managed Disk with Id: $($md.Id)"
             $md | Remove-AzDisk -Force
             Write-Host "Deleted unattached Managed Disk with Id: $($md.Id) "
         }else{
             $md.Id
         }
     }
 }

Unattached Azure unmanaged disk

 Connect-Azaccount
 Get-Azsubscription
 Select-Azsubscrciption -Subscription "Subscription Name"
 # Set deleteUnattachedVHDs=1 if you want to delete unattached VHDs
 # Set deleteUnattachedVHDs=0 if you want to see the Uri of the unattached VHDs
 $deleteUnattachedVHDs=0
 $storageAccounts = Get-AzStorageAccount
 foreach($storageAccount in $storageAccounts){
     $storageKey = (Get-AzStorageAccountKey -ResourceGroupName $storageAccount.ResourceGroupName -Name $storageAccount.StorageAccountName)[0].Value
     $context = New-AzStorageContext -StorageAccountName $storageAccount.StorageAccountName -StorageAccountKey $storageKey
     $containers = Get-AzStorageContainer -Context $context
     foreach($container in $containers){
         $blobs = Get-AzStorageBlob -Container $container.Name -Context $context
         #Fetch all the Page blobs with extension .vhd as only Page blobs can be attached as disk to Azure VMs
         $blobs | Where-Object {$_.BlobType -eq 'PageBlob' -and $_.Name.EndsWith('.vhd')} | ForEach-Object {
             #If a Page blob is not attached as disk then LeaseStatus will be unlocked
             if($_.ICloudBlob.Properties.LeaseStatus -eq 'Unlocked'){
                     if($deleteUnattachedVHDs -eq 1){
                         Write-Host "Deleting unattached VHD with Uri: $($_.ICloudBlob.Uri.AbsoluteUri)"
                         $_ | Remove-AzStorageBlob -Force
                         Write-Host "Deleted unattached VHD with Uri: $($_.ICloudBlob.Uri.AbsoluteUri)"
                     }
                    else{
                         $_.ICloudBlob.Uri.AbsoluteUri
                     }
             }
         }
     }
 }

Unattached Azure NIC

 Connect-Azaccount
 Get-Azsubscription
 Select-Azsubscrciption -Subscription "Subscription Name"
 Get-AzNetworkInterface | ? {$_.VirtualMachine -is $null}

Azure Monitor and Log Analytics

This option is for big environments in Azure. There are commitment tiers for Azure Monitor and Log Analytics starting from 100 GB logs per day. If you consume that much – you can purchase commitment tiers and start saving from 15% to 30%.

Additional details could be found at Pricing page 

Azure VM Autoscale

This feature allows to add more compute power when you need it and reduce to minimum when it is not required. That might happen manually, or automatically based on schedule or other metrics.

The example list of criteria that can be used for auto-scale:

  • Percentage CPU
  • Network In/Out
  • Disk Read/Write Bytes
  • Disk Read/Write Operations/Sec

The benefit here is to pay only for what you use and when it is necessary. You can also limit the number of minimum and maximum instances for scaling.

Azure Storage tiers

Azure allow to use storage in various forms and types. The most popular are Blob Storage and File Share. There are different tiers for Blob Storage that define costs, performance and use cases. Those are the tiers available:

  • Hot – Optimized for storing data that is accessed frequently. Details
  • Cool – Optimized for storing data that is infrequently accessed and stored for at least 30 days. Details
  • Archive – Optimized for storing data that is rarely accessed and stored for at least 180 days with flexible latency requirements, on the order of hours. Details

Blob storage lifecycle management offers a rich, rule-based policy that you can use to transition your data to the best access tier and to expire data at the end of its lifecycle You can configure policies to move blobs between tiers and data deletion automatically to achieve the optimal costs/performance level.

There is even a video available on Microsoft Azure YouTube channel with the detailed explanation.

Create budgets and allocate costs to different teams and projects

With Azure Cost Management you can set up budgets to plan and proactively manage spending. You can configure alerts based on your cost to be notified that your spend is within your defined spend limit. When the budget thresholds are exceeded, only notifications are triggered. None of your resources isn’t stopped. You can use budgets to compare and track spending as you analyse costs.

There is a good tutorial explains how to work with budgets step-by-step. It is pretty straight forward.

Spot VMs

Spot Virtual Machines allow to buy unused capacity in Azure with a low level price. These kind of VM’s are great for a temporary workload like dev\test environments. They also suits well for jobs resistant for interruptions like batch or queue processing.

I use Spot VM as a Jump Host for Cloud engineers team. Don’t need it often. but when I need to login – start the VM and it get ready for use quickly. Done with the task – shutdown. Even if you forget – it will be evicted soon or stopped by schedule at the end of working hours.

You can always find more details about Azure Spot VM’s here 

Azure Data Factory data flows reserved capacity

Using reserved capacity, you make a commitment for azure Data FActory data flow usage for a period 1-3 years to receive a descent discount on the compute costs. You need to know Azure region, compute type, number of cores and for how many years you want to purchase.

As other reservation, this one works the same way – as a pool. That means, you do not need to assign the reservation to a specific factory or integration runtime. Existing factories or newly deployed factories automatically get the benefit straight after purchase as far as the reservation attributes are match.

There is an option to cancel, refund or exhange revervations. Please find more details here.

If would like to discover more about the data flow reservation, please see this article: Understand Azure Reservations discount

Use Infrastructure as Code for resource provisioning

IaC helps to provision resources in Azure quickly and every time you use it you will get exactly the same result. That is way quicker than using Portal. You can store your code in a GitHub repository, collaborate on writing, use version control and re-use your code when you need this code. Takes a while to get used to, but benefits worth it. It also lowers a potential human error during provisioning. Same template could be used to create Dev, Test and Prod environments.

There are multiple options you can use to describe your Infrastructure as Code:

There are additional IaC tools that can be used. You can bring your existing skills and tools, including
Ansible and Chef, to provision and manage Azure infrastructure directly.

Leave a Reply

Your email address will not be published. Required fields are marked *