Convert OnDemand VMs to Spot VMs in Azure Virtual Machine Scalesets
- Covers all Virtual Machine Scalesets within a Subscription, but that can be controlled with environment variable - CONVERT_TO_SPOT and tags
- For each VMSS, converts all OD VMs to Spot VMs except one OD VM
- Identifies a OD VM that can be replaced
- Copies properties for all dependencies - Network Interface, VM, Health Extension and creates a new Spot VM of the same type
- Then the OD VM is deleted
- If it can't find the same VM type, it will roll back all changes
- Azure credentials need to be provided as environment variables
- CONVERT_TO_SPOT variable can accept three values
- ALL - This will convert all Virtual Machine Scaleset regardless of its tag
- TRUE - This will convert only Virtual Machine Scalesets with tag - convert_to_spot = True
- FALSE - Virtual Machine Scalesets with tag convert_to_spot = False will be skipped, everything else will be converted
- This task is scheduled to run every hour at the first minute for eg. 9:01, 10:01 and so on
git clone https://github.com/vwake7/azure-spotter
cd azure-spotter
docker build -t azurespot-local-image .
docker rm --force azurespot-local
docker run -d --name azurespot-local \
-e AZURE_TENANT_ID="tenant_id" \
-e AZURE_CLIENT_ID="client_id" \
-e AZURE_CLIENT_SECRET="secret" \
-e AZURE_SUBSCRIPTION_ID="subscription_id" \
-e CONVERT_TO_SPOT="ALL" \
azurespot-local-image
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
- This project is built with stackql as the IaC tool and this has helped to simplify the code to a great extent
- This project is inspired by AutoSpotting