This repository is for my blog post Run Azure Functions on Virtual Machine Scale Sets. Read it for more context and background.
This repository contains an example of how you can run Azure Functions on Azure VM scale-sets (VMSS).
This example uses a spot VM based VM scale set. If you pick your region and SKU well, you can run your workloads on the cheap. Save 💰.
Some stuff baked into this example:
- The VMSS defaults to the
Standard_D2as_v4
SKU. It's really cheap right now (May 2022) in theWest US 2
region. - The Azure Functions Host version 4.3.0 is used.
- The ARM template deploys a load balancer so that HTTP triggers are accessible. This might not be needed if your app just uses queue or timer triggers.
- The VMSS uses the
2022-datacenter-core-smalldisk
Windows Server Core image from Microsoft, i.e. the code runs on Windows not Linux. - HTTP triggers are accessible via port 80. No HTTPS and certificate stuff is considered. This is not ideal.
- Remote Desktop (RDP) is not enabled in the network security group or load balancer. The only port forwarded is port 80.
- The installation script uses the .NET 6.0 runtime to run the host and load the app in-process.
- An emphemeral OS disk is used with the largest available placement per SKU. Hopefully your app doesn't need much disk space.
- Deployment files (Azure Functions host, app zip, app environment variables, scripts) from previous deployments are never cleaned up.
- The auto-scale is performed based on (relatively sensitive) CPU thresholds. Nothing fancy like KEDA is implemented.
- The auto-scale settings have a minimum of 1 instance and a maximum of 30 instances (configurable).
Publish your Functions app and zip the publish directory. Put your configuration in a environment file (.env). Deploy it to a spot VM scale set.
After the deployment completes, go to the domain name associated with one of your load balancer resources, e.g.
http://az-func-vmss-ub6loiqgi5bga-0.southcentralus.cloudapp.azure.com/api/hello
The resources in Azure Portal will look something like this:
There is no warranty at all. Do this at your own risk.
YMMV.
("YMMV" is enough to wash my hands of whatever trouble you kids get yourself into, right?)