-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patheks-node-groups.tf
108 lines (86 loc) · 3.21 KB
/
eks-node-groups.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Create IAM role for EKS Node Group
resource "aws_iam_role" "nodes_general" {
# The name of the role
name = "eks-node-group-general"
# The policy that grants an entity permission to assume the role.
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "amazon_eks_worker_node_policy_general" {
# The ARN of the policy you want to apply.
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
# The role the policy should be applied to
role = aws_iam_role.nodes_general.name
}
resource "aws_iam_role_policy_attachment" "amazon_eks_cni_policy_general" {
# The ARN of the policy you want to apply.
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
# The role the policy should be applied to
role = aws_iam_role.nodes_general.name
}
resource "aws_iam_role_policy_attachment" "amazon_ec2_container_registry_read_only" {
# The ARN of the policy you want to apply.
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
# The role the policy should be applied to
role = aws_iam_role.nodes_general.name
}
resource "aws_eks_node_group" "nodes_general" {
# Name of the EKS Cluster.
cluster_name = aws_eks_cluster.eks.name
# Name of the EKS Node Group.
node_group_name = "nodes-general"
# Amazon Resource Name (ARN) of the IAM Role that provides permissions for the EKS Node Group.
node_role_arn = aws_iam_role.nodes_general.arn
# Identifiers of EC2 Subnets to associate with the EKS Node Group.
# These subnets must have the following resource tag: kubernetes.io/cluster/CLUSTER_NAME
# (where CLUSTER_NAME is replaced with the name of the EKS Cluster).
subnet_ids = [
aws_subnet.private_1.id,
aws_subnet.private_2.id
]
# Configuration block with scaling settings
scaling_config {
# Desired number of worker nodes.
desired_size = 1
# Maximum number of worker nodes.
max_size = 1
# Minimum number of worker nodes.
min_size = 1
}
# Type of Amazon Machine Image (AMI) associated with the EKS Node Group.
# Valid values: AL2_x86_64, AL2_x86_64_GPU, AL2_ARM_64
ami_type = "AL2_x86_64"
# Type of capacity associated with the EKS Node Group.
# Valid values: ON_DEMAND, SPOT
capacity_type = "ON_DEMAND"
# Disk size in GiB for worker nodes
disk_size = 20
# Force version update if existing pods are unable to be drained due to a pod disruption budget issue.
force_update_version = false
# List of instance types associated with the EKS Node Group
instance_types = ["t3.small"]
labels = {
role = "nodes-general"
}
# Kubernetes version
version = "1.19"
# Ensure that IAM Role permissions are created before and deleted after EKS Node Group handling.
# Otherwise, EKS will not be able to properly delete EC2 Instances and Elastic Network Interfaces.
depends_on = [
aws_iam_role_policy_attachment.amazon_eks_worker_node_policy_general,
aws_iam_role_policy_attachment.amazon_eks_cni_policy_general,
aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only,
]
}