With Azure Net SDK, how to create a Azure Spot VM. I did some research and just found how to create it via Azure Portal or arm template.
With Azure Net SDK, how to create a Azure Spot VM. I did some research and just found how to create it via Azure Portal or arm template.
You need to create them as you normally would, but specify the eviction policy for the vm. That would be the way to create spot instance
Here is a sample code to create a Azure Spot VM
/// <summary>
/// Create a Spot VM
/// </summary>
/// <param name="vmSizeName">Name of the size of the VM</param>
/// <param name="spotBiddingMaximumPrice">Specifies the maximum price you are willing to pay for a Azure Spot VM/VMSS (use -1 to match on-demand pricing)</param>
/// <param name="deallocateOnEviction">If set, when the Spot VM is evicted, it will be automatically deallocated (recommended!).</param>
/// <returns>VMProperties instance</returns>
public static VMProperties CreateSpotVM(string vmSizeName, double spotBiddingMaximumPrice = -1, bool deallocateOnEviction = true)
=> new VMProperties()
{
Hardware = new VMHardwareProfile(vmSizeName),
SpotVMBillingProfile = new VMBillingProfile(spotBiddingMaximumPrice),
SpotVMEvictionPolicy = (deallocateOnEviction ? "Deallocate" : null)
};