在创建 EKS Node Group 时,可以通过添加 Launch Template 或 Launch Configuration 来调整容器最大可用 Pod 数量(maxPods)的值,如下所示:
resource "aws_launch_template" "example" {
name = "example-launch-template"
image_id = "ami-0abc123"
instance_type = "t2.micro"
user_data = <<-EOF
#!/bin/bash
echo "Hello, World!" > index.html
nohup busybox httpd -f -p 8080 &
EOF
}
resource "aws_eks_node_group" "example" {
cluster_name = aws_eks_cluster.example.name
node_group_name = "example-node-group"
node_role_arn = aws_iam_role.example.arn
subnet_ids = [aws_subnet.example.id]
launch_template = {
id = aws_launch_template.example.id
version = "$Latest"
}
scaling_config {
desired_size = 2
max_size = 2
min_size = 2
}
remote_access {
ec2_ssh_key = aws_key_pair.example.key_name
source_security_group_ids = [aws_security_group.example.id]
}
tags = {
Terraform = "true"
Environment = "test"
}
capacity_type = "ON_DEMAND"
max_pods = 30
}
在上面的示例中,我们通过 max_pods 参数将容器最大可用 Pod 数量调整为 30。
resource "aws_launch_configuration" "example" {
name = "example-launch-configuration"
image_id = "ami-0abc123"
instance_type = "t2.micro"
user_data = <<-EOF
#!/bin/bash
echo "Hello, World!" > index.html
nohup busybox httpd -f -p 8080 &
EOF
}
resource "aws_eks_node_group" "example" {
cluster_name = aws_eks_cluster.example.name
node_group_name = "example-node-group"
node_role_arn = aws_iam_role.example.arn