【发布时间】:2019-08-25 02:28:58
【问题描述】:
我正在使用 mixed instances policy 设置一个 Auto Scaling 组 (ASG) 以使用多种 Spot 实例类型。如何限制我的 ASG 使用的 Spot 实例池的数量?
Spot Instance pools定义如下:
一组具有相同实例类型(例如,
m5.large)、操作系统、可用区和网络平台的未使用的 EC2 实例。
我了解,就我而言,Spot 实例池基本上是一对不同的可用区和实例类型。
我的 CloudFormation 模板使用混合实例策略创建一个包含 16 个实例的 Auto Scaling 组。它使用四种实例类型和所有可用区。测试区域us-west-2 有四个可用区。理论上,该组应该能够使用多达 16 个现场实例池。
堆栈的SpotInstancePools 参数设置ASG 的同名属性。我尝试将其设置为各种值,但它似乎并不能直接控制 ASG 使用的 Spot 实例池的数量。
CloudFormation 模板:
AWSTemplateFormatVersion: '2010-09-09'
Description: Testing mixed instance policies
Parameters:
SpotInstancePools:
Type: Number
Default: 1
Description: The ASG's number of spot instance pools.
ImageId:
Type: AWS::EC2::Image::Id
Default: ami-061392db613a6357b
Description: Launch template's AMI. Defaults to Amazon Linux 2.
Resources:
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones: !GetAZs
MaxSize: 16
MinSize: 16
MixedInstancesPolicy:
InstancesDistribution:
OnDemandAllocationStrategy: prioritized
OnDemandBaseCapacity: 0
OnDemandPercentageAboveBaseCapacity: 0
SpotAllocationStrategy: lowest-price
SpotInstancePools: !Ref SpotInstancePools
SpotMaxPrice: ''
LaunchTemplate:
LaunchTemplateSpecification:
LaunchTemplateId: !Ref LaunchTemplate
Version: !GetAtt LaunchTemplate.LatestVersionNumber
Overrides:
- InstanceType: t2.small
- InstanceType: t3.small
- InstanceType: t2.medium
- InstanceType: t3.medium
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
ImageId: !Ref ImageId
创建堆栈的命令mixed-instances-policy-test-1,其 SpotInstancePools 计数为 1:
aws cloudformation create-stack \
--stack-name mixed-instances-policy-test-1 \
--template-body file://mixed-instances-policy.yaml \
--parameters ParameterKey=SpotInstancePools,ParameterValue=1 \
--region us-west-2 \
--profile test
创建堆栈的命令mixed-instances-policy-5,其 SpotInstancePools 计数为 5:
aws cloudformation create-stack \
--stack-name mixed-instances-policy-test-5 \
--template-body file://mixed-instances-policy.yaml \
--parameters ParameterKey=SpotInstancePools,ParameterValue=5 \
--region us-west-2 \
--profile test
列出使用的唯一 Spot 实例池数量的命令(根据需要替换堆栈名称):
aws ec2 describe-instances \
--filters 'Name=tag:aws:cloudformation:stack-name,Values=mixed-instances-policy-test-1' \
--query 'Reservations[].Instances[].[InstanceType, Placement.AvailabilityZone]' \
--output text \
--region us-west-2 \
--profile test |
sort |
uniq --count
在等待每个堆栈完成创建后,我会检查唯一 Spot 实例池的数量。
SpotInstancePools 设置为 1,我看到 3 个唯一池。
5 t2.small us-west-2a
5 t3.small us-west-2b
6 t3.small us-west-2c
SpotInstancePools 设置为 5,我看到 11 个唯一池。
2 t2.medium us-west-2a
1 t2.medium us-west-2b
1 t2.medium us-west-2c
2 t2.small us-west-2a
2 t2.small us-west-2b
1 t2.small us-west-2c
1 t3.medium us-west-2a
1 t3.medium us-west-2b
1 t3.medium us-west-2c
2 t3.small us-west-2b
2 t3.small us-west-2c
在每种情况下,我希望池的数量等于参数值。
【问题讨论】:
标签: amazon-web-services amazon-ec2 autoscaling amazon-ec2-spot-market