How to schedule to change VM resources in azure? - azure

I have 4 VMs in azure and I am trying to set up a schedule to lower the RAMs and CPU cores for after-hours and revert them back to their original size during business hours.
can someone guide me through the steps or share a how-to resource, please? I can't find any documents and I am sure my search key is not correct.
Thanks

As suggested by #harshavmb, you can make use of VMSS.
In Azure, Auto-Scaling is possible if you make use of Virtual Machine Scale-Sets.
Virtual Machine Scale-Sets allows you to automatically scale as resource demand changes.
Based on schedules, you can create auto scale rules.
These schedule-based rules allow you to automatically scale the number of VM resources at fixed times.
To create the Auto-Scale rule, you can make use of following tools:
Azure PowerShell
Azure CLI
Azure template
Otherwise, you can create an automation account in Azure and execute runbooks as mentioned in below link if helpful:
Automatically Resize an Azure VM - Automation account

Related

Downgrading Azure Resources during weekends using PowerShell Automation

In order to save expenses in Azure DevOps, I'm trying to scale the resources, which can scale depending on the requirement. Team leads will update the resource requirements in SharePoint, and the runbook needs to be executed with SharePoint datat. Team leads will update the resource requirements in SharePoint, and the runbook needs to be executed with SharePoint data. If such resources are not required on weekends but must be operational on weekdays, they should be stopped or reduced in size. I need to use automation to do it for all of the VMs and App Services at a subscription level every Friday. If there is a method to automate this procedure using PowerShell.
I'm glad to receive input. Thanks in advance.
I'm looking for feedback on Start/Stop VMs and Scaling Azure App Services. On weekends, the same may be said for other relevant resources. How can we accomplish this with Azure PowerShell?
 
The best way to do is by using 'Azure Automation Runbook' scheduled to run every specified day or date by time. To target the VM's, Azure Tags will be much helpful.
Your script must check:
A VM has a specific Tags (e.g., StopVM:Friday 11:00PM)
Maintenance Enabled in your monitoring solution
VM is stopped already or not.
Backup required?
Confirm the VM is Deallocated (not stopped)
Auto-Shutdown option is also available to do this activity.
Because sometime all you need is a quick and dirty way to save money :
And if you wan't to build something there's an API to shutdown and start VMs

Azure VM auto scale based on alert

The scenario is as follows:
In company premise, there is a network that consists few machines.
The company has an Azure subscription.
Requirement:
To monitor the company's Network/Machines via Azure
If the company resource goes beyond a threshold limit then trigger alerts. Example, network bandwidth consumption, machine CPU/Memory usage, etc.
When such alerts occur then spin up new virtual machines or VM scale sets in Azure to handle the load.
The purpose is if the machines in on-prem goes above threshold limit then automatically provision VMs in Azure, as there are only few on-prem machines.
Please guide how to implement these use cases?
your question is a little confusing. You mention machines on premises and using Azure to monitor them. You can monitor on premises VMs using Azure but then you mention provisioning new Azure VMs via Scale Sets.
I'm not 100% where your workload is but assuming it is in Azure then if you are using VM Scale Sets it's very easy to scale in and out based on resource utilisation.
This can be configured as described here: https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-autoscale-portal

Vertical auto-scaling Azure VM

Recently, i have been introduced to Azure and i have an application that is using high CPU (almost 80%) during morning hours between 9 am to 1 pm. After that the CPU utilization is reduced to a minimal of 10% the whole day. So in order to reduce my cost i was thinking to implement vertical auto-scaling in my application. When i read more on this i could find automation account and RunBook as the only way but my need is that is there any other way to implement Vertical auto-scaling in Azure IaaS VM apart from automation account?
If Yes, please share the approach.
Yes you can use Azure PowerShell and/or the Azure CLI to execute scaling commands on a VM. Here are some PowerShell examples: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/resize-vm?toc=%2Fazure%2Fvirtual-machines%2Fwindows%2Ftoc.json
You would then just have to schedule the script to run either locally or in an Azure service like Functions, Container Instances or etc.
If you wanted to scale vertically a single VM based on a performance metric (CPU, memory, etc.) you can use the classic metric alerts system to do that. When those alerts fire based on thresholds you set you can invoke a webhook OR Logic App to trigger execution of a script or ARM Template.

how can I configure availability sets in azure?

I am not very familiar with this in azure.
I created one centos vm, I created an availability set, in order to enable auto scaling I need to create another VM in the same availability set.
so I will create another vm, with the same image.
So, these 2 vms will replicate each other? if I install something in one VM, will it be replicated automatically to the other vm?, should I use only one of the vms as the starter point to install and configure things?
or should I do everything manually on each VM? Example, if I open port 80 in one I should do it in another?, if I install magento in one, I should install it in the other?
Azure will not replicate your VMs automatically. There are some manual steps involved:
You need to prepare one VM as a starter point.
Then you manually clone VMs up to a maximum number that you will need.
Make sure all they are in the same availability set.
Set up auto scaling
Now Azure will scale automatically by turning some of your VMs on and off. When VM is turned off, you will only incur storage costs for it. And storage in Azure is almost free.
To answer your first question: How to configure availability set
I created a post covering this on How to guard your application from azure outages
Use the quick create to stand up a VM of your choice
Once the instance is running click on the configure tab and create a new availability set
Click save
Saving will force a shut down, reconfigure, startup process
Once the VM comes back online you can create a 2nd VM
Using the create from gallery option, click through all the create screens until you get to the configure virtual machine screen (screen 4 at the moment)
Select the cloud service that was created with your first VM (availability sets require the VM's to run in the same cloud service)
Then select the availability set you created for the first VM
Finish the creation of your second VM
You can now see the linked VM's in the same availability set by clicking on the configure tab for any VM in the availability set you created. It will list all VMs in a given availability set inside the details of the VM

How to autoscale virtual machines(IaaS approach) in azure

How to autoscale virtual machines(IaaS approach) in azure instead of web/worker role autoscaling in azure?
You can now Autoscale Virtual machines in Azure directly in the Azure Management Portal. ScottGu has a post about it on his blog.
The important thing to autoscale VM's is you must proactively provision the Max # of VM's you think you'll need to handle your peak capacity, and add them to the same availability set.
For example, if on the busiest day of the week it takes 6 machines to handle all of your traffic, then you need to create 6 instances and install your application on it, configure it to handle traffic etc.... and then add it to an availability set with the other 5 machines.
Once you've done this, you can navigate to the Cloud Service that contains all of your virtual machines and click on the Scale tab. You should see a list of your availability sets, and it should tell you the # of machines you can scale over. Choose a metric (either CPU or Queue today), and then range of machines you want to scale between. You can scale between 1 and the total # of machines.
When load is low -- Azure will turn off machines (so you don't have to pay for them), and when load is high, Azure will turn those machines back on.
Auto-scaling on the IaaS level doesn't really make sense. Even if azure could detect high CPU usage and start a new VM based on it, what then? you still need to install your application on that VM automatically somehow.
What you are looking for is something that runs your app on azure, and installs new instances on new VM's if necessary. That "something" is called PaaS enabler. Basically it is another abstraction level between your app and the azure IaaS.
there are a couple of them out there :
Cloudify, CloudFoundary, Juju
as far as i know, only one that supports Azure is Cloudify. you can check out how to configure azure using Cloudify here : Configuring Azure
you can also check out the community - Cloudify Forum, or post questions here for assistance.
Disclaimer: I work for Gigaspaces, developing the Cloudify product line.
According to this it's possible to scale out IaaS with Availability sets by pre-provisioning the number of boxes: https://blogs.msdn.microsoft.com/kaevans/2015/02/20/autoscaling-azurevirtual-machines/

Resources