vol*_*wei 6 terraform amazon-eks terraform0.12+ terraform-aws-modules
我使用terraform-aws-eks 模块创建了一个 AWS EKS 集群。Terraform 版本是 1.0.6,aws 提供程序版本是 3.60.0。通过这些版本,我应该能够使用aws_autoscaling_group_tag资源来标记 EKS 创建的 ASG。
我的问题是模块中的节点组是地图的映射(此处描述),我不知道如何迭代我的节点组以标记其中的所有 ASG。这是来自 terraform 的示例:
resource "aws_eks_node_group" "example" {
cluster_name = "example"
node_group_name = "example"
# ... other configuration ...
}
resource "aws_autoscaling_group_tag" "example" {
for_each = toset(
[for asg in flatten(
[for resources in aws_eks_node_group.example.resources : resources.autoscaling_groups]
) : asg.name]
)
autoscaling_group_name = each.value
tag {
key = "k8s.io/cluster-autoscaler/node-template/label/eks.amazonaws.com/capacityType"
value = "SPOT"
propagate_at_launch = false
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,有一个特定的节点组。但就我而言,有 3 个节点组,我希望所有 ASG 都被标记。到目前为止,我还没有对 terraform 中的循环进行过太多研究,我什至不确定它是否会起作用。我很感激任何帮助!
你提到你使用terraform-aws-eks module. 当您使用该模块时,节点组(托管或自管理)的定义是该模块的一部分。该模块基本上使用子模块eks-management-node-group并且该子模块支持标记。该模块创建启动模板和基于这些模板的 ASG 组。
您不需要在模块外部标记 ASG。你最好不要这样做,因为它会改变你的基础设施配置:下次你在terraform-aws-eks模块代码上运行 apply 时,标签可能会改变。
您的配置应该如下所示:
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 18.0"
..
..
# EKS Managed Node Group(s)
eks_managed_node_group_defaults = {
tags = {
"k8s.io/cluster-autoscaler/node-template/label/eks.amazonaws.com/capacityType" = "SPOT"
}
}
eks_managed_node_groups = {
blue = {}
green = {
min_size = 1
max_size = 10
desired_size = 1
instance_types = ["t3.large"]
}
}
Run Code Online (Sandbox Code Playgroud)
随意指定标签eks_managed_node_group_defaults适用于所有节点组。如果您希望它们不同,您可以为每个节点组(在上面的示例中为蓝色和绿色)进行配置。
请注意,使用tags意味着所有创建的资源都将被标记。我不认为这是有问题的,但如果你这样做,那么这里需要一个不同的解决方案。
这是子模块所有支持的输入的链接。
您可以查看模块文档以获取更多示例。
如果我理解正确的话,您想要创建容量类型为 SPOT 实例的 ASG 组。该terraform-aws-eks模块具有capacity_type描述为与 EKS 节点组关联的容量类型的参数。有效值:ON_DEMAND,SPOT
然后,实现您想要的目标就简单得多:
eks_managed_node_group_defaults = {
capacity_type = "SPOT"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2551 次 |
| 最近记录: |