【发布时间】:2021-07-21 15:14:55
【问题描述】:
我使用的是 0.14.2 Terraform 版本。我正在尝试使用以下代码部署具有两个节点的 EKS 集群:
resource "aws_eks_cluster" "cluster" {
enabled_cluster_log_types = []
name = var.cluster_name
role_arn = aws_iam_role.cluster.arn
version = var.eks_version
vpc_config {
subnet_ids = flatten([ aws_subnet.private.*.id, aws_subnet.public.*.id ])
security_group_ids = []
endpoint_private_access = "true"
endpoint_public_access = "true"
}
tags = var.tags[terraform.workspace]
depends_on = [
aws_iam_role_policy_attachment.cluster_AmazonEKSClusterPolicy,
aws_iam_role_policy_attachment.cluster_AmazonEKSServicePolicy,
aws_cloudwatch_log_group.cluster
]
}
resource "aws_launch_configuration" "eks-managenodes" {
for_each = local.ob
name_prefix = "${var.cluster_name}-launch-${each.value}"
image_id = "ami-038341f2c72928ada"
instance_type = "t3.medium"
user_data = <<-EOF
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh ${var.cluster_name}
EOF
root_block_device {
delete_on_termination = true
volume_size = 30
volume_type = "gp2"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "eks-asg" {
for_each = local.ob
desired_capacity = 1
launch_configuration = aws_launch_configuration.eks-managenodes[each.value].id
max_size = 1
min_size = 1
name = "${var.cluster_name}-node-${each.value}"
vpc_zone_identifier = aws_subnet.private.*.id
tag {
key = "Name"
value = "eks-manage-node-${each.value}"
propagate_at_launch = true
}
tag {
key = "kubernetes.io/cluster/${var.cluster_name}"
value = "owned"
propagate_at_launch = true
}
depends_on = [
aws_launch_configuration.eks-managenodes,
aws_eks_cluster.cluster
]
}
然后,集群部署正常,ASG和EC2实例部署正常,但问题是这些实例没有附加到相应的集群,我没有发现问题..
有什么想法吗? 谢谢
【问题讨论】:
标签: amazon-web-services kubernetes terraform amazon-eks