Created
April 4, 2020 19:02
-
-
Save blogumi/b1bdee54d57010a49660fe2396d70b90 to your computer and use it in GitHub Desktop.
Now we have everything in place to create and manage EC2 instances that will serve as our worker nodes in the Kubernetes cluster. This setup uses an EC2 AutoScaling Group (ASG) rather than manually working with EC2 instances. This offers flexibility to scale up and down the worker nodes on demand when used in conjunction with AutoScaling policie…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_ami" "eks-worker" { | |
filter { | |
name = "name" | |
values = ["amazon-eks-node-${aws_eks_cluster.demo.version}-v*"] | |
} | |
most_recent = true | |
owners = ["602401143452"] # Amazon EKS AMI Account ID | |
} | |
# This data source is included for ease of sample architecture deployment | |
# and can be swapped out as necessary. | |
data "aws_region" "current" { | |
} | |
# EKS currently documents this required userdata for EKS worker nodes to | |
# properly configure Kubernetes applications on the EC2 instance. | |
# We implement a Terraform local here to simplify Base64 encoding this | |
# information into the AutoScaling Launch Configuration. | |
# More information: https://docs.aws.amazon.com/eks/latest/userguide/launch-workers.html | |
locals { | |
demo-node-userdata = <<USERDATA | |
#!/bin/bash | |
set -o xtrace | |
/etc/eks/bootstrap.sh --apiserver-endpoint '${aws_eks_cluster.demo.endpoint}' --b64-cluster-ca '${aws_eks_cluster. demo.certificate_authority[0].data}' '${var.cluster-name}' | |
USERDATA | |
} | |
resource "aws_launch_configuration" "demo" { | |
associate_public_ip_address = true | |
iam_instance_profile = aws_iam_instance_profile.demo-node.name | |
image_id = data.aws_ami.eks-worker.id | |
instance_type = "m4.large" | |
name_prefix = "terraform-eks-demo" | |
security_groups = [aws_security_group.demo-node.id] | |
user_data_base64 = base64encode(local.demo-node-userdata) | |
lifecycle { | |
create_before_destroy = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment