如何命名使用 terraform 配置的 eks 工作节点? [英] How can I name eks worker nodes provisioned with terraform?
问题描述
我正在使用 terraform 12.20.0,并且我已经配置了一个具有 2 个节点组的 EKS 集群.
I am using terraform 12.20.0 and I have provisioned an EKS cluster with 2 node groups.
如何根据节点组名称为 EKS 节点工作器添加名称标签?
How can I add name tags to EKS node workers according to their node group names?
我尝试添加名称"标签在每个节点组的附加标签部分,但标签没有,我的 EC2 实例名称为空,而其他标签出现.
I have tried adding "Name" tag in the additional tag sections of each node-group but the tags did not take and my EC2 instance names are empty, while other tags appear.
这是配置 - 我跳过了不太相关的部分:
Here is the configuration - I have skipped the less relevant bits:
module "eks-cluster" {
...
node_groups_defaults = {
disk_size = 128
key_name = var.key_name
subnets = [
aws_subnet.{{}}.id,
aws_subnet.{{}}.id,
]
k8s_labels = {
env = var.environment
}
additional_tags = {
env = var.environment
"k8s.io/cluster-autoscaler/enabled" = "true"
"k8s.io/cluster-autoscaler/${var.cluster-name}" = "true"
}
}
node_groups = {
app = {
name = "app"
.....
k8s_labels = {
nodegroup = "app"
}
additional_tags = {
nodegroup = "app"
Name = "${var.environment}-app-node"
}
}
ml = {
name = "ml"
...
instance_type = "m5.xlarge"
k8s_labels = {
nodegroup = "ml"
}
additional_tags = {
nodegroup = "ml"
Name = "${var.environment}-ml-node"
}
}
}
tags = {
env = var.environment
}
map_roles = [{
......
}]
}
推荐答案
根据 文档 资源:aws_eks_node_group
不允许修改实例上的标签.
As per documentation Resource: aws_eks_node_group
doesn't allow for modifying tags on your instances.
EKS 节点组即将推出一项不错的功能,允许您传递自定义用户数据脚本.使用它,您将能够以编程方式为您的实例修改标签.可以跟踪问题 ->https://github.com/aws/containers-roadmap/issues/596
There is a nice feature coming soon to EKS node groups which will allow you to pass a custom userdata script. Using that you will be able to modify programatically tags for your instances. Issues can be tracked -> https://github.com/aws/containers-roadmap/issues/596
更新:自 20/08/2020 起,您现在可以在您的节点组中使用 launch_template
.这将允许您传入 Name
标签.示例:
UPDATE:
As of 20/08/2020, you can now utilise launch_template
with your node group. This will allow you to pass in Name
tag. Example:
resource "aws_launch_template" "cluster" {
image_id = data.aws_ssm_parameter.cluster.value
instance_type = "t3.medium"
name = "eks-launch-template-test"
update_default_version = true
tag_specifications {
resource_type = "instance"
tags = {
Name = "eks-node-group-instance-name"
}
}
}
这篇关于如何命名使用 terraform 配置的 eks 工作节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!