Spot 实例 - Eksctl 用户指南

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Spot 实例

托管节点组

eksctl支持使用 EKS 托管节点组的竞价型工作节点,该功能允许拥有容错应用程序的 EKS 客户轻松地为其 EKS 集群配置和管理 EC2 竞价型实例。EKS Managed Nodegroup 将按照竞价最佳实践配置和启动由竞价型实例组成的 EC2 自动扩缩组,并在实例被 AWS 中断之前自动耗尽竞价型工作节点。使用此功能不收取增量费用,客户只需为使用 AWS 资源(例如 EC2 竞价型实例和 EBS 卷)付费。

要使用竞价型实例创建带有托管节点组的集群,请传递该--spot标志和可选的实例类型列表:

eksctl create cluster --spot --instance-types=c3.large,c4.large,c5.large

要在现有集群上使用竞价型实例创建托管节点组,请执行以下操作:

eksctl create nodegroup --cluster=<clusterName> --spot --instance-types=c3.large,c4.large,c5.large

要通过配置文件使用托管节点组创建 Spot 实例,请执行以下操作:

# spot-cluster.yaml apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: spot-cluster region: us-west-2 managedNodeGroups: - name: spot instanceTypes: ["c3.large","c4.large","c5.large","c5d.large","c5n.large","c5a.large"] spot: true # `instanceTypes` defaults to [`m5.large`] - name: spot-2 spot: true # On-Demand instances - name: on-demand instanceTypes: ["c3.large", "c4.large", "c5.large"]
eksctl create cluster -f spot-cluster.yaml
注意

非托管节点组不支持spotinstanceTypes字段,而是使用该instancesDistribution字段来配置竞价型实例。见下文

进一步信息

非托管节点组

eksctl已通过 Auto Scaling Grou MixedInstancesPolicy ps 支持竞价型实例。

以下是使用 50% 竞价型实例和 50% 按需实例的节点组示例:

nodeGroups: - name: ng-1 minSize: 2 maxSize: 5 instancesDistribution: maxPrice: 0.017 instanceTypes: ["t3.small", "t3.medium"] # At least one instance type should be specified onDemandBaseCapacity: 0 onDemandPercentageAboveBaseCapacity: 50 spotInstancePools: 2

请注意,使用该nodeGroups.X.instanceType字段时不应设置该instancesDistribution字段。

此示例使用 GPU 实例:

nodeGroups: - name: ng-gpu instanceType: mixed desiredCapacity: 1 instancesDistribution: instanceTypes: - p2.xlarge - p2.8xlarge - p2.16xlarge maxPrice: 0.50

此示例使用容量优化的竞价分配策略:

nodeGroups: - name: ng-capacity-optimized minSize: 2 maxSize: 5 instancesDistribution: maxPrice: 0.017 instanceTypes: ["t3.small", "t3.medium"] # At least one instance type should be specified onDemandBaseCapacity: 0 onDemandPercentageAboveBaseCapacity: 50 spotAllocationStrategy: "capacity-optimized"

此示例使用现 capacity-optimized-prioritized货分配策略:

nodeGroups: - name: ng-capacity-optimized-prioritized minSize: 2 maxSize: 5 instancesDistribution: maxPrice: 0.017 instanceTypes: ["t3a.small", "t3.small"] # At least two instance types should be specified onDemandBaseCapacity: 0 onDemandPercentageAboveBaseCapacity: 0 spotAllocationStrategy: "capacity-optimized-prioritized"

使用capacity-optimized-prioritized分配策略,然后在启动模板覆盖列表中按从最高到最低优先级(列表中的第一个到最后)设置实例类型的顺序。Amazon A EC2 uto Scaling 会尽最大努力尊重实例类型优先级,但会首先针对容量进行优化。对于必须最大限度地减少中断可能性的工作负载来说,这是一个不错的选择,但对某些实例类型的偏好也很重要。有关更多信息,请参阅 ASG 购买选项。

请注意,使用该spotInstancePools字段时不应设置该spotAllocationStrategy字段。如果未指定,则 EC2 将默认使用该lowest-price策略。spotAllocationStrategy

以下是一个最小的例子:

nodeGroups: - name: ng-1 instancesDistribution: instanceTypes: ["t3.small", "t3.medium"] # At least one instance type should be specified

要区分竞价型实例和按需型实例之间的节点,您可以使用 kubernetes 标签node-lifecycle,该标签将具有值spoton-demand取决于其类型。

实例分布中的参数

有关详细信息,请参阅集群配置架构。