我使用的是 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 实例部署正常,但问题是这些实例没有附加到相应的集群,我没有发现问题..
有什么想法吗? 谢谢
答案 0 :(得分:1)
节点可能因多种原因无法加入集群。
调试步骤:
通过 SSH 连接到一个节点并检查 /var/log/cloud-init.log
和 /var/log/cloud-init-output.log
以确保它没有错误地完成。
验证 kubelet
和 aws-node
进程是否正在 ec2 节点上运行。两者都应该出现在 ps
检查 /etc/eks/bootstrap.sh
是否存在。尝试使用源自 AWS ui 中 EKS 概览页面的变量,以根用户身份调用它,参数为 /etc/eks/bootstrap.sh --apiserver-endpoint '${endpoint}' --b64-cluster-ca '${cluster_ca_data}' '${cluster_name}'
。
检查 aws-auth
中的 kube-system
配置映射并验证 ec2 角色映射如下:
mapRoles: |
- rolearn: arn:aws:iam::<account id>:role/<node role>
username: system:node:{{EC2PrivateDNSName}}
groups:
- system:bootstrappers
- system:nodes
如果没有这个,节点将无法向集群进行身份验证。
如有疑问,请尝试使用适用于您集群的 kubernetes 版本的最新版 EKS ami - 一些 AMI 已损坏。
答案 1 :(得分:0)
为了让 EKS 集群拥有这些节点,您将不得不使用 AWS EKS Node Group 而不是 EC2 Launch Configuration 我相信。
从下面文档中的同一链接,cluster_name 将引用您创建的 EKD 集群。
resource "aws_eks_node_group" "example" {
cluster_name = aws_eks_cluster.example.name
node_group_name = "example"
node_role_arn = aws_iam_role.example.arn
subnet_ids = aws_subnet.example[*].id
scaling_config {
desired_size = 1
max_size = 1
min_size = 1
}