I'm trying to deploy an AWS environment using terraform. The EC2 instances and the cluster is created fine, but it fails when trying to join the instances with the cluster.
Error: error waiting for EKS Node Group (env-dev:node_1) to create: unexpected state 'CREATE_FAILED', wanted target 'ACTIVE'. last error: 1 error occurred:
* i-022a2d319d457ab83, i-0374c9efbb32b1f0f, i-05b42da747ca0c8cd, i-08439b352ff4bcc5f, i-0d286addbf2eedd2a, i-0dc6f1bd12b372427, i-0ed373f52f9e27510: NodeCreationFailure: Instances failed to join the kubernetes cluster
According to CloudWatch, this is where it fails
"responseObject": {
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "Node \"ip-10-206-68-167.eu-west-1.compute.internal\" is invalid: metadata.labels: Invalid value: \"ip-10-206-68-167.xxxx-xxxxxxxxxxxxxxxxxxxxx-xxxx-xxx.eu-west-1.a\": must be no more than 63 characters",
"reason": "Invalid",
"details": {
"name": "ip-10-206-68-167.eu-west-1.compute.internal",
"kind": "Node",
"causes": [
{
"reason": "FieldValueInvalid",
"message": "Invalid value: \"ip-10-206-68-167.xxxx-xxxxxxxxxxxxxxxxxxxxx-xxxx-xxx.eu-west-1.a\": must be no more than 63 characters",
"field": "metadata.labels"
}
]
},
"code": 422
}
Is there any way to override the hostname using terraform?
EDIT:
Snippet of the terraform:
variable "db_subnet_ids" { default = ["subnet-04f6e659f2b2851f2", "subnet-0a42b2ec54b5aa143"] }
resource "aws_eks_cluster" "cluster" {
enabled_cluster_log_types = [
"api",
"audit",
"authenticator",
"controllerManager",
"scheduler",
]
name = "env-${var.suffix}"
role_arn = aws_iam_role.eks_cluster_role.arn
vpc_config {
subnet_ids = var.db_subnet_ids
security_group_ids = [aws_security_group.cluster_http.id, aws_security_group.cluster_https.id]
}
depends_on = [
aws_iam_role_policy_attachment.AmazonEKSWorkerNodePolicy,
aws_iam_role_policy_attachment.AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.AmazonEC2ContainerRegistryReadOnly,
]
}
resource "aws_eks_node_group" "cluster" {
cluster_name = aws_eks_cluster.cluster.name
node_group_name = "node_1"
node_role_arn = aws_iam_role.eks_nodes_role.arn
subnet_ids = var.db_subnet_ids
scaling_config {
desired_size = 7
max_size = 7
min_size = 7
}
ami_type = "AL2_x86_64"
capacity_type = "ON_DEMAND"
disk_size = 50
instance_types = ["t3.large"]
depends_on = [
aws_iam_role_policy_attachment.AmazonEKSWorkerNodePolicy,
aws_iam_role_policy_attachment.AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.AmazonEC2ContainerRegistryReadOnly,
]
}
The VPC is created manually, so the configuration is as so:
Subnet ID: subnet-04f6e659f2b2851f2
Name: xxxx-xxxxxxxxxxxxxxxxxxxxx-xxxx-xxx-private-eu-west-1a
IPv4 CIDR: 10.206.68.160/28
Subnet ID: subnet-0a42b2ec54b5aa143
Name: xxxx-xxxxxxxxxxxxxxxxxxxxx-xxxx-xxx-private-eu-west-1b
IPv4 CIDR: 10.206.68.176/28
And the VPC
Name: xxxx-xxxxxxxxxxxxxxxxxxxxx-xxxx-xxx
VIP ID: vpc-09a3e88350a018cbf
IPv4 CIDR: 10.206.68.160/27
DHCP options set ID: dopt-0ea3823bed3d5ff2c
DHCP options set
ID: dopt-0ea3823bed3d5ff2c
Name: xxxx-xxxxxxxxxxxxxxxxxxxxx-xxxx-xxxx
Name later altered to: xxxx-xx-xxxx-xxxx (2nd word shortened) Explanation in my answer below.
CodePudding user response:
The issue is somewhat resolved. Not sure I'm a big fan of the solution, but it works.
So the node hostnames was created by appending
- IP address
- DHCP options set name of from the VPC
- Not exactly sure where "eu-west-1" and "a" derives from.
Region of the VPC perhaps? And the "a" from the subnet?
which it ended up with something like:
ip-10-206-68-167.xxxx-xxxxxxxxxxxxxxxxxxxxx-xxxx-xxx.eu-west-1.a
So by shortening the DHCP options set name, the hostnames was therefore shortened as well, and everything is working just fine.