Skip to content

Managed Node Groups with Launch Template using Spot Instances: Taints #1214

@cabrinha

Description

@cabrinha

I have issues

I'm submitting a...

  • bug report
  • feature request
  • support request - read the FAQ first!
  • kudos, thank you, warm fuzzy

What is the current behavior?

Creating a Managed Node Group does allow using Spot Instances and setting additional k8s labels on the node, but doesn't seem to allow specifying taints using kubelet_extra_args.

If this is a bug, how to reproduce? Please include a code sample if relevant.

working from the example: https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/launch_templates_with_managed_node_groups

Adding kubelet_extra_args to the template_file

data "template_file" "nginx" {
  template = file("${path.module}/templates/userdata.sh.tpl")

  vars = {
    cluster_name        = local.cluster_name
    endpoint            = module.eks.cluster_endpoint
    cluster_auth_base64 = module.eks.cluster_certificate_authority_data

    bootstrap_extra_args = ""
    kubelet_extra_args   = "--node-labels=node.kubernetes.io/lifecycle=spot,group=nginx,role=ingress-controllers --register-with-taints=dedicated=ingress-controllers:NoSchedule"
  }
}

resource "aws_launch_template" "nginx" {
  name_prefix             = "eks-nginx-"
  description            = "NGINX Launch-Template"
  update_default_version = true

  block_device_mappings {
    device_name = "/dev/xvda"

    ebs {
      volume_size           = 10
      volume_type           = "gp2"
      delete_on_termination = true
    }
  }

  key_name = "cabrinha-mng-test"

  monitoring {
    enabled = true
  }

  network_interfaces {
    associate_public_ip_address = false
    delete_on_termination       = true
    security_groups             = [
      module.eks.cluster_primary_security_group_id,
      module.eks.cluster_security_group_id,
      module.eks.worker_security_group_id,
    ]
  }

  user_data = base64encode(
    data.template_file.nginx.rendered,
  )

  # Supplying custom tags to EKS instances is another use-case for LaunchTemplates
  tag_specifications {
    resource_type = "instance"

    tags = {
      Name = "${local.cluster_name}-nginx"
    }
  }

  # Supplying custom tags to EKS instances root volumes is another use-case for LaunchTemplates. (doesnt add tags to dynamically provisioned volumes via PVC tho)
  tag_specifications {
    resource_type = "volume"

    tags = {
      Name = "${local.cluster_name}-nginx"
    }
  }

  # Tag the LT itself
  tags = {
    Name = "${local.cluster_name}-nginx"
  }

  lifecycle {
    create_before_destroy = true
  }
}

module "eks" {
 ...

  node_groups = {
    nginx = {
      capacity_type    = "SPOT"
      desired_capacity = 3
      max_capacity     = 3
      min_capacity     = 3

      launch_template_id      = aws_launch_template.nginx.id
      launch_template_version = aws_launch_template.nginx.default_version

      instance_types = [
        "c3.2xlarge",
        "c4.xlarge",
        "c4.2xlarge",
        "c5.2xlarge",
        "c5.xlarge",
        "c5.4xlarge",
        "m3.xlarge",
        "m3.2xlarge",
        "m4.2xlarge",
        "m5.4xlarge",
        "m5a.xlarge",
        "m5d.4xlarge",
        "r3.large",
        "r4.2xlarge",
        "r5.xlarge",
        "r5.2xlarge",
        "r5.4xlarge",
        "t3a.xlarge",
        "t3a.2xlarge",
        "t3.2xlarge",
      ]
    }
  }
}

This results in NodeCreationFailure with Instances failed to join the kubernetes cluster in the AWS console.

What's the expected behavior?

Is there any way to using managed node groups, with spot instances, with taints?

Are you able to fix this problem and submit a PR? Link here if you have already.

Environment details

  • Affected module version:
  • OS: macOS 10.15.7
  • Terraform version: 0.12.30

Any other relevant info

#1211

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions