sigs.k8s.io/cluster-api-provider-azure@v1.14.3/docs/book/src/topics/spot-vms.md (about) 1 # Spot Virtual Machines 2 3 [Azure Spot Virtual Machines](https://learn.microsoft.com/azure/virtual-machines/spot-vms) allow users to reduce the costs of their 4 compute resources by utilising Azure's spare capacity for a lower price. 5 6 With this lower cost, comes the risk of preemption. 7 When capacity within a particular Availability Zone is increased, 8 Azure may need to reclaim Spot Virtual Machines to satisfy the demand on their data centres. 9 10 ## When should I use Spot Virtual Machines? 11 12 Spot Virtual Machines are ideal for workloads that can be interrupted. 13 For example, short jobs or stateless services that can be rescheduled quickly, 14 without data loss, and resume operation with limited degradation to a service. 15 16 ## How do I use Spot Virtual Machines? 17 18 To enable a Machine to be backed by a Spot Virtual Machine, add `spotVMOptions` 19 to your `AzureMachineTemplate`: 20 21 ```yaml 22 apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 23 kind: AzureMachineTemplate 24 metadata: 25 name: capz-md-0 26 spec: 27 location: westus2 28 template: 29 osDisk: 30 diskSizeGB: 30 31 managedDisk: 32 storageAccountType: Premium_LRS 33 osType: Linux 34 sshPublicKey: ${YOUR_SSH_PUB_KEY} 35 vmSize: Standard_B2s 36 spotVMOptions: {} 37 ``` 38 39 You may also add a `maxPrice` to the options to limit the maximum spend for the 40 instance. It is however, recommended **not** to set a `maxPrice` as Azure will 41 cap your spending at the on-demand price if this field is left empty and you will 42 experience fewer interruptions. 43 44 ```yaml 45 spec: 46 template: 47 spotVMOptions: 48 maxPrice: 0.04 # Price in USD per hour (up to 5 decimal places) 49 ``` 50 51 In addition, you are able to explicitly set the eviction policy for the Spot VM. 52 The default policy is `Deallocate` which will deallocate the VM when it is 53 evicted. You can also set the policy to `Delete` which will delete the VM when 54 it is evicted. 55 56 ```yaml 57 spec: 58 template: 59 spotVMOptions: 60 evictionPolicy: Delete # or Deallocate 61 ``` 62 63 The experimental `MachinePool` also supports using spot instances. To enable a `MachinePool` to be backed by spot instances, add `spotVMOptions` to your `AzureMachinePool` spec: 64 65 ```yaml 66 apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 67 kind: AzureMachinePool 68 metadata: 69 name: capz-mp-0 70 spec: 71 location: westus2 72 template: 73 osDisk: 74 diskSizeGB: 30 75 managedDisk: 76 storageAccountType: Premium_LRS 77 osType: Linux 78 sshPublicKey: ${YOUR_SSH_PUB_KEY} 79 vmSize: Standard_B2s 80 spotVMOptions: {} 81 ```