When using AWS EKS
, is it possible to set up the worker nodes on spot instances?
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}