sigs.k8s.io/cluster-api-provider-aws@v1.5.5/docs/book/src/topics/spot-instances.md (about)

     1  # Spot Instances
     2  
     3  [AWS Spot Instances](https://aws.amazon.com/ec2/spot/?cards.sort-by=item.additionalFields.startDateTime&cards.sort-order=asc&trk=a9b30b20-d23f-4d61-9452-c51a7e407fcd&sc_channel=ps&sc_campaign=acquisition&sc_medium=ACQ-P|PS-GO|Brand|Desktop|SU|Compute|EC2%20Spot|IN|EN|Text&s_kwcid=AL!4422!3!517651795636!e!!g!!amazon%20ec2%20spot&ef_id=Cj0KCQiA95aRBhCsARIsAC2xvfxB17BKyQFcn9UUKZ1GT2sfvxKyhboEKa87gl8wBO37fSrNXmx52cIaAtqwEALw_wcB:G:s&s_kwcid=AL!4422!3!517651795636!e!!g!!amazon%20ec2%20spot) allows user to reduce the costs of their compute resources by utilising AWS spare capacity for a lower price.
     4  
     5  Because Spot Instances are tightly integrated with AWS services such as Auto Scaling, ECS and CloudFormation, users can choose how to launch and maintain their applications running on Spot Instances.
     6  
     7  Although, with this lower cost, comes the risk of preemption. When capacity within a particular Availability Zone is increased, AWS may need to reclaim Spot instances to satisfy the demand on their data centres.
     8  
     9  ## When to use spot instances? 
    10  
    11  Spot instances are ideal for workloads that can be interrupted. For example, short jobs or stateless services that can be rescheduled quickly, without data loss, and resume operation with limited degradation to a service.
    12  
    13  ## Using Spot Instances with AWSMachine
    14  
    15  To enable AWS Machine to be backed by a Spot Instance, users need to add `spotMarketOptions` to AWSMachineTemplate:
    16  ```yaml
    17  apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    18  kind: AWSMachineTemplate
    19  metadata:
    20    name: ${CLUSTER_NAME}-md-0
    21  spec:
    22    template:
    23      spec:
    24        iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io
    25        instanceType: ${AWS_NODE_MACHINE_TYPE}
    26        spotMarketOptions:
    27          maxPrice: ""
    28        sshKeyName: ${AWS_SSH_KEY_NAME}
    29  ```
    30  Users may also add a `maxPrice` to the options to limit the maximum spend for the instance. It is however, recommended not to set a maxPrice as AWS will cap your spending at the on-demand price if this field is left empty, and you will experience fewer interruptions.
    31  ```yaml
    32  spec:
    33    template:
    34      spotMarketOptions:
    35        maxPrice: 0.02 # Price in USD per hour (up to 5 decimal places)
    36  ```
    37  
    38  ## Using Spot Instances with AWSManagedMachinePool
    39  To use spot instance in EKS managed node groups for a EKS cluster, set `capacityType` to `spot` in `AWSManagedMachinePool`.
    40  ```yaml
    41  apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    42  kind: AWSManagedMachinePool
    43  metadata:
    44    name: ${CLUSTER_NAME}-pool-0
    45  spec:
    46    capacityType: spot
    47    ...
    48  ```
    49  
    50  See [AWS doc](https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html) for more details.
    51  
    52  > **IMPORTANT NOTE**: The experimental feature `AWSMachinePool` does not support using spot instances as of now.