在我的Bootstrap脚本中需要有什么才能将节点加入我的EKS群集?
我正在为节点组使用启动模板,并且我遇到一个错误,说nodecreationfailure:实例未能加入Kubernetes cluster
,我的问题似乎是我需要一个bootstrap脚本来加入节点到集群。 找到的示例
这是我的用户数据脚本,这是我从此文档 linux_user_data.tpl 脚本尝试#1
#!/bin/bash
set -e
${pre_bootstrap_user_data ~}
export SERVICE_IPV4_CIDR=${cluster_service_ipv4_cidr}
B64_CLUSTER_CA=${cluster_auth_base64}
API_SERVER_URL=${cluster_endpoint}
/etc/eks/bootstrap.sh ${cluster_name} ${bootstrap_extra_args} --b64-cluster-ca $B64_CLUSTER_CA --apiserver-endpoint $API_SERVER_URL
${post_bootstrap_user_data ~}
脚本尝试#2
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh mtc-cluster
脚本尝试#3
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh --apiserver-endpoint ${aws_eks_cluster.eks.endpoint} --b64-cluster-ca ${aws_eks_cluster.eks.certificate_authority}
这是我在Terraform中的启动模板,应该使用此用户数据脚本
resource "aws_launch_template" "node" {
image_id = var.image_id
instance_type = var.instance_type
key_name = var.key_name
name = var.name
user_data = base64encode("linux_user_data.tpl")
block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 20
}
}
}
这是我的节点组资源块
resource "aws_eks_node_group" "nodes_eks" {
cluster_name = aws_eks_cluster.eks.name
node_group_name = "eks-node-group"
node_role_arn = aws_iam_role.eks_nodes.arn
subnet_ids = module.vpc.private_subnets
scaling_config {
desired_size = 3
max_size = 6
min_size = 3
}
ami_type = "CUSTOM"
capacity_type = "ON_DEMAND"
force_update_version = false
launch_template {
id = aws_launch_template.node.id
version = aws_launch_template.node.default_version
}
depends_on = [
aws_iam_role_policy_attachment.amazon_eks_worker_node_policy,
aws_iam_role_policy_attachment.amazon_eks_cni_policy,
aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only,
]
}
I'm using a launch template for my node group and I'm getting an error saying NodeCreationFailure: Instances failed to join the kubernetes cluster
It seems that my issue is I need a bootstrap script to join the nodes to the cluster. This is my user data script, which is an example I found from this doc
linux_user_data.tpl
Script attempt #1
#!/bin/bash
set -e
${pre_bootstrap_user_data ~}
export SERVICE_IPV4_CIDR=${cluster_service_ipv4_cidr}
B64_CLUSTER_CA=${cluster_auth_base64}
API_SERVER_URL=${cluster_endpoint}
/etc/eks/bootstrap.sh ${cluster_name} ${bootstrap_extra_args} --b64-cluster-ca $B64_CLUSTER_CA --apiserver-endpoint $API_SERVER_URL
${post_bootstrap_user_data ~}
Script attempt #2
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh mtc-cluster
Script attempt #3
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh --apiserver-endpoint ${aws_eks_cluster.eks.endpoint} --b64-cluster-ca ${aws_eks_cluster.eks.certificate_authority}
Here's my launch template in Terraform that's supposed to use this user data script
resource "aws_launch_template" "node" {
image_id = var.image_id
instance_type = var.instance_type
key_name = var.key_name
name = var.name
user_data = base64encode("linux_user_data.tpl")
block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 20
}
}
}
Here's my node group resource block as well
resource "aws_eks_node_group" "nodes_eks" {
cluster_name = aws_eks_cluster.eks.name
node_group_name = "eks-node-group"
node_role_arn = aws_iam_role.eks_nodes.arn
subnet_ids = module.vpc.private_subnets
scaling_config {
desired_size = 3
max_size = 6
min_size = 3
}
ami_type = "CUSTOM"
capacity_type = "ON_DEMAND"
force_update_version = false
launch_template {
id = aws_launch_template.node.id
version = aws_launch_template.node.default_version
}
depends_on = [
aws_iam_role_policy_attachment.amazon_eks_worker_node_policy,
aws_iam_role_policy_attachment.amazon_eks_cni_policy,
aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only,
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据问题和文档中发布的代码,第二个示例应起作用。但是,我认为文件扩展名可能是绊倒加入群集的节点。在第一次和第三次尝试中定义的脚本需要使用
templateFile
函数[1],因为该值无法在脚本上提供否则,即使在文档[2]中正确定义了插值,即使插值定义正确[2]在为节点提供配置时,是几种可能性。由于您使用的是Amazon Linux 2,因此应遵循[3]中的说明。在这种情况下,您可以使用以下模板使用
templateFile
函数(让我们使用已经拥有的名称,linux_user_data.tpl
):由于K8S版本
1.24 < /code>将Docker放弃为容器运行时,
- 集装箱-Runtime
设置为Containerd
。关于功能,没有差异,但是这种方式(如果您不部署1.24)可以缓解过渡。在aws_launch_template
资源中,您将不得不更改以下内容:文档说唯一必需的参数是群集名称,因此请尝试此操作并在需要时进行相应更新。还要注意
path.root
用法,这意味着TemplateFile
将在模块根部所在的同一目录中查找文件。如果要模块化代码,则可以切换到path.module
。有关路径
的更多信息,请参见[4]。编辑:为了使Bootstrap脚本按预期工作,必须使用EKS优化的AMI。每个区域的AMI ID可以在[5]中找到。
[1] https://www.terraform.io/language/language/language/functions/functions/templatefile
[2] https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html#launch-template-plate-user-data
[3] https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html#launch-template-template-custom-ami
[4] [4] https://www.terraform.io/language/language/leferences/references#filesystem-and-workspace-info
[5] [5] https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html
Based on the code posted in the question and the documentation, the second example should work. However, I think that the file extension is what might be tripping up the nodes joining the cluster. The scripts defined in the first and third attempt require using the
templatefile
function [1] as the values cannot be provided to the script otherwise, even with interpolation defined properly as inThe documentation [2] says that there are a couple of possibilities when providing the configuration to the nodes. Since you are using Amazon Linux 2, you should follow the explanation in [3]. In this case, you can use the
templatefile
function with the following template (let's use the name you already have,linux_user_data.tpl
):Since K8s version
1.24
is abandoning Docker as container runtime, the--container-runtime
is set tocontainerd
. With regard to functionality, there are no differences but this way (if you are not deploying 1.24) it will ease the transition. In theaws_launch_template
resource, you would then have to change the following:The documentation says the only required argument is the cluster name, so try with this and update accordingly if needed. Also note the
path.root
usage, which means thetemplatefile
will look for a file in the same directory where the root of the module is. If you were to modularize the code, then you could switch topath.module
. More information aboutpath
can be found in [4].EDIT: In order for the bootstrap script to work as expected, an EKS optimized AMI has to be used. The AMI ID per region can be found in [5].
[1] https://www.terraform.io/language/functions/templatefile
[2] https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html#launch-template-user-data
[3] https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html#launch-template-custom-ami
[4] https://www.terraform.io/language/expressions/references#filesystem-and-workspace-info
[5] https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html