Amazon EKS: Setting up worker nodes on spot instances

10/19/2018

When using AWS EKS, is it possible to set up the worker nodes on spot instances?

  • How can I do this?
  • Anything special I should pay attention to, in such a setup?
-- Lior Bar-On
amazon-ec2
amazon-web-services
aws-eks
kubernetes

1 Answer

10/19/2018

Yes, you can, you will have to modify the Cloudformation Template (which is mentioned in this document) in the LaunchConfiguration section to specify a spot price.

NodeLaunchConfig:
  Type: AWS::AutoScaling::LaunchConfiguration
  Properties:
    SpotPrice: "20" # <=== Here
    AssociatePublicIpAddress: 'true'
    IamInstanceProfile: !Ref NodeInstanceProfile
    ImageId: !Ref NodeImageId
    InstanceType: !Ref NodeInstanceType
    KeyName: !Ref KeyName
    SecurityGroups:
    - !Ref NodeSecurityGroup
    BlockDeviceMappings:
      - DeviceName: /dev/xvda
        Ebs:
          VolumeSize: !Ref NodeVolumeSize
          VolumeType: gp2
          DeleteOnTermination: true
    UserData:
      Fn::Base64:
        !Sub |
          #!/bin/bash
          set -o xtrace
          /etc/eks/bootstrap.sh ${ClusterName} ${BootstrapArguments}
          /opt/aws/bin/cfn-signal --exit-code $? \
                   --stack  ${AWS::StackName} \
                   --resource NodeGroup  \
                   --region ${AWS::Region}
-- Rico
Source: StackOverflow