[英]How should I configure an AWS Auto-Scalling Group mixed_instances_policy to only allow for spot_instances with multiple EC2 instance_types?
I have an AWS Auto-Scalling Group that spawns (or shuts down) one EC2 machine based on the amount of messages in a specific SQS Queue.我有一个 AWS Auto-Scalling Group,它根据特定 SQS 队列中的消息量生成(或关闭)一台 EC2 机器。 That works as expected, but sometimes I get the following error:这按预期工作,但有时我会收到以下错误:
Launching a new EC2 instance.启动新的 EC2 实例。 Status Reason: Could not launch Spot Instances.状态原因:无法启动 Spot 实例。 InsufficientInstanceCapacity - There is no Spot capacity available that matches your request. InsufficientInstanceCapacity - 没有与您的请求相匹配的 Spot 容量。 Launching EC2 instance failed.启动 EC2 实例失败。
A DevOps guy I know told me to " increase the amount of spot_instance_pools to 20 and add some more instance_types ".我认识的一个 DevOps 人告诉我“将 spot_instance_pools 的数量增加到 20 并添加更多的 instance_types ”。
I did some research and found that the default number of spot_instance_pools is 2 .我做了一些研究,发现spot_instance_pools 的默认数量是 2 。 That same number is shown on AWS Console. AWS 控制台上显示了相同的数字。 Whenever I have this problem, I deploy a new script changing the EC instance type and it works, so both those suggestions seems like a valid ones to me.每当我遇到这个问题时,我都会部署一个更改 EC 实例类型的新脚本并且它可以工作,所以这两个建议对我来说似乎都是有效的。
The problem is that my current Terraform script does not have the enclosing mixed_instances_policy
and I'm unsure how to configure it to keep only on_spot
instances (since they are cheaper) and no on_demand
instances.问题是我当前的 Terraform 脚本没有封闭的mixed_instances_policy
,我不确定如何配置它以仅保留on_spot
实例(因为它们更便宜)而没有on_demand
实例。 So far I have come up with:到目前为止,我想出了:
mixed_instances_policy = {
on_demand_percentage_above_base_capacity = 0
spot_instance_pools = 20
}
Keeping the other values inside mixed_instances_policy
with the defaults should suffice for me.将mixed_instances_policy
的其他值与默认值保持mixed_instances_policy
对我来说就足够了。
But I did not understand how to configure the mixed_instances_policy launch_template .但我不明白如何配置mix_instances_policy launch_template 。 Is it nested within mixed_instances_policy
?它是否嵌套在mixed_instances_policy
? Should I add a mixed_instances_policy launch_template override too?我也应该添加一个mix_instances_policy launch_template 覆盖吗? Or perhaps a launch_template_specification或者也许是一个launch_template_specification
TL;DR; TL; 博士;
How do I configure an AWS Auto-Scalling Group mixed_instances_policy to only allow for spot_instances with multiple EC2 instance_types?如何配置 AWS Auto-Scalling 组 mix_instances_policy 以仅允许具有多个 EC2 instance_types 的 spot_instances?
The on_demand_percentage_above_base_capacity = 0
line is the one you want. on_demand_percentage_above_base_capacity = 0
行是您想要的。 Based on the doc you shared and the structure in the AWS doc , I'd say it probably goes inside instances_distribution
That tells the ASG to launch 0% on demand (aka 100% spot).根据您共享的文档和AWS 文档中的结构,我会说它可能在instances_distribution
它告诉ASG 按需启动0%(也就是100% 现货)。 Within the mixed_instances_policy
you need to add overrides
for the instance types you're adding (weights are optional. Weight is the number of desired capacity units that instance type counts as).在mixed_instances_policy
您需要为要添加的实例类型添加overrides
(权重是可选的。权重是实例类型计入的所需容量单位数)。
Also, the number of spot pools doesn't mater much for your use case.此外,现货池的数量对您的用例来说并不重要。 That's saying /if everything is available/ launch up to that many different spot types per AZ.也就是说/如果一切都可用/启动到每个可用区的许多不同的点类型。 Having more pools does help a bit with availability though, because if one pool becomes supply constrained, then you won't have all your instances terminated at once, but it doesn't impact being able to launch at all.不过,拥有更多池确实对可用性有所帮助,因为如果一个池变得供应受限,那么您将不会立即终止所有实例,但这根本不会影响能够启动。
Actually, if you want cheaper cost, you want the number lower.事实上,如果你想要更便宜的成本,你想要的数字更低。 Because if you have allocation strategy as 'cheapest first' then you want few pools per AZ (since its only the cheapest few pools then).因为如果您将分配策略设为“最便宜的优先”,那么您需要每个可用区的几个池(因为那时它只是最便宜的几个池)。 If there's only 1 instance type available in the AZ, its going to launch that one regardless.如果 AZ 中只有 1 个实例类型可用,则无论如何都会启动该实例类型。 So the number of overrides you select is the important part to maintain availability when launching.因此,您选择的覆盖数量是启动时保持可用性的重要部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.