使用 Spot 实例部署 EKS 集群时出错

问题描述

所以我使用 terraform 模块来部署混合实例的 EKS 集群。这是有问题的模块,第三个示例是我需要做的:https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/docs/spot-instances.md

我的代码

worker_groups_launch_template = [
{
  name                 = "linux-nodes"
  instance_type        = var.instance_type_l
  asg_min_size         = var.min_size
  asg_desired_capacity = var.desired_size
  asg_max_size         = var.max_size
  asg_recreate_on_change = true
  platform             = "linux"
  public_ip            = false
  root_encrypted       = true
  root_kms_key_id      = var.kms_key_arn
  on_demand_base_capacity = var.on_demand_base_capacity
  on_demand_percentage_above_base_capacity = var.on_demand_percentage_above_base_capacity
  spot_instance_pools  = var.spot_instance_pools

  kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=`curl -s http://169.254.169.254/latest/Meta-data/instance-life-cycle`"

  tags = [
    {
      "key"                 = "k8s.io/cluster-autoscaler/enabled"
      "propagate_at_launch" = "false"
      "value"               = "true"
    },{
      "key"                 = "k8s.io/cluster-autoscaler/${var.cluster_name}"
      "propagate_at_launch" = "false"
      "value"               = "true"
    },{
      "key"                 = "k8s.io/cluster-autoscaler/node-template/label/os"
      "value"               = "linux"
      "propagate_at_launch" = "true"
    }        
  ]
}]

我得到的错误

    Error: Invalid index
  on ../terraform-aws-eks/workers_launch_template.tf line 292,in resource "aws_launch_template" "workers_launch_template":
 292:     var.worker_groups[count.index],|----------------
    | count.index is 0
    | var.worker_groups is empty tuple
The given key does not identify an element in this collection value.

我不明白为什么它会抱怨 worker_groups,因为我使用的是 worker_groups_launch_template。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)