user20208419
user20208419

Reputation: 323

How to add label to the EKS nodes with the Terraform EKS module?

I use the EKS module, https://github.com/terraform-aws-modules/terraform-aws-eks.

The code as follows launches two EC2 instances and tags the instances and launch template. I would like to label these two EKS nodes as AL2Nodes = "monitor". How to do it?

Note: I can see the tags added to these EC2 instances. But, when I do kubectl get nodes --show-labels, I cannot find the label, AL2Nodes = "monitor".

module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "18.29.1"

  cluster_name    = var.cluster_name
  cluster_version = var.cluster_version

  cluster_endpoint_private_access = true
  cluster_endpoint_public_access  = true
  vpc_id                          = var.vpc_id
  subnet_ids                      = var.subnet_ids

  node_security_group_additional_rules = {
    ingress_nodes_karpenter_port = {
      description                   = "Cluster API to Node group for Karpenter webhook"
      protocol                      = "tcp"
      from_port                     = 8443
      to_port                       = 8443
      type                          = "ingress"
      source_cluster_security_group = true
    }
  }

  node_security_group_tags = {
    "karpenter.sh/discovery/${var.cluster_name}" = var.cluster_name
  }

  eks_managed_node_groups = {
    "${var.cluster_name}" = {
      capacity_type  = "ON_DEMAND"

      instance_types = ["m5.large"]
      # Not required nor used - avoid tagging two security groups with same tag as well
      create_security_group = false

      # Ensure enough capacity to run 2 Karpenter pods
      min_size     = 2
      max_size     = 3
      desired_size = 2

      iam_role_additional_policies = [
        "arn:${local.partition}:iam::aws:policy/AmazonSSMManagedInstanceCore", # Required by Karpenter
      ]

      tags = {
        # This will tag the launch template created for use by Karpenter
        "karpenter.sh/discovery/${var.cluster_name}" = var.cluster_name
        AL2Nodes                                     = "monitor"
      }
    }
  }
}

Upvotes: 2

Views: 2445

Answers (1)

Tynchtyk
Tynchtyk

Reputation: 126

Here is the example how to to add labels on node_groups:

eks_managed_node_groups = {
    "${var.cluster_name}" = {
        ...
        labels = {
            AL2Nodes = "monitor"
        }
        ...
    }
}

Click here to see the example from public module

Upvotes: 3

Related Questions