Currently Azure Virtual Machine Scale Sets (VMSS) doesn't support custom logic based auto scaling.
This solution was developed for real customer need, It based on Azure Function App which triggered by timer and samples ServiceBus or SQL Database stored procedure to get current load on VMSS, Azure Function then adds or removes VMs accordingly to configured threshold.
Please select the samples product: ServiceBus or SQL Database in the concole application project or in the Azure Function project.
You can clone this repo and create your own custom logic, just create a new class library and implement ILoadWatcher interface.
There's also console app for testing locally.
- Azure Function App
- VMSS
- Register a new application in Azure Active Directory (need to be global admin in order to do that)
- Create application Key, save this secret, you will need that later for deployment
- Give the application "Owner" role on VMSS
- Install Visual Studio Tools for Azure Functions
- Create SQL Database and/or ServiceBus Topics or and Q.
- Create Application Insights.
- These paramters decides if input data is X & Y will the scaling will be up with Z VM'S or down.
- Please decide where to store the scaling logic parameters to be store, the options are Database or File.
- Open solution in visual studio 2015 update 3
- Build solution
- Publish Azure Function project named "vmssAutoScale" into your Azure Function App
- Set Azure Function App settings:
<appSettings>
<add key="MaxScale" value="maximum server capacity limit"/>
<add key="MinScale" value="minimum server capacity limit"/>
<add key="MaxThreshold" value="maximum threshold for auto scale, above this value autoscaler will add one server to vmss"/>
<add key="MinThreshold" value="minimum threshold for auto scale, below this value autoscaler will remove one server to vmss"/>
<add key="SQLConnectionString" value="sql server connection string which holds logic for autoscale"/>
<add key="ClientId" value="application key in azure active directory"/>
<add key="ClientSecret" value="application secret in azure active directory"/>
<add key="TenantId" value="active directory id"/>
<add key="SubscriptionId" value="azure subscription id which holds vmss"/>
<add key="ResourceGroup" value="vmss resource group"/>
<add key="VmssName" value="vmss name"/>
<add key="AzureArmApiBaseUrl" value="https://management.azure.com/"/>
<add key="VmssApiVersion" value="2016-03-30"/>
</appSettings>