I'm looking for some help regarding scaling an Azure App Service during deployments. The main challenge is that I need to turn off scaling rules and scale the app down to a single instance before deployment. Currently, we have been manually adjusting the settings, but there's a frustrating issue with the Azure UI—it doesn't allow overlapping schedule times for scaling. For instance, if you try to set a scale-out time from 2 PM to 5 PM and another one from 5 PM to 7 PM, it automatically adjusts the overlapping period to 4:59 PM, causing the app to briefly return to the default rule of 1 instance, which is not ideal.
What I need is to programmatically set the app to manual scaling at 1 instance before deployment and then revert to our saved scaling rules after the deployment finishes. I've attempted various methods to achieve this—whether through PowerShell scripts, Azure DevOps add-ins, or even HTTP-triggered functions—but none have worked reliably. Any recommendations or solutions would be greatly appreciated!
5 Answers
One approach could be to add two additional stages to your deployment pipeline. First, set the instance count to 1, then push the code, and finally set the instance count back to whatever your desired auto-scaling policy is. If you're using Infrastructure as Code (IaC), you might need a different approach to properly manage the auto-scaling state.
The overlapping time issue with Azure autoscale settings is pretty well known. The direct JSON edit you mentioned bypasses the UI limitation, but it seems like automating that process around deployments is still where the complexity lies.
But doesn't this risk causing problems? Scaling down while instances are actively handling requests might hurt the user experience during deployments.
I've found a workaround for managing scaling profiles. You don’t need to set an end time for your profiles; Azure will evaluate and hold the settings until the next profile kicks in. You can use these commands:
1. Set autoscale to manual:
```
az monitor autoscale update --resource-group your-resource-group --name "Autoscale Rules" --enabled false
```
2. Set the instance count to 1:
```
az appservice plan update --resource-group your-group --name your-plan --number-of-workers 1
```
After deployment, you can re-enable the auto-scaling rules without worrying about the overlapping times.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically