-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcastai.tf
More file actions
219 lines (185 loc) · 6.21 KB
/
castai.tf
File metadata and controls
219 lines (185 loc) · 6.21 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# 3. Connect EKS cluster to CAST AI.
locals {
role_name = "castai-eks-role"
}
# Configure Data sources and providers required for CAST AI connection.
data "aws_caller_identity" "current" {}
resource "castai_eks_user_arn" "castai_user_arn" {
cluster_id = castai_eks_clusterid.cluster_id.id
}
provider "castai" {
api_url = var.castai_api_url
api_token = var.castai_api_token
}
provider "helm" {
kubernetes = {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
exec = {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
# This requires the awscli to be installed locally where Terraform is executed.
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name, "--region", var.cluster_region]
}
}
}
# Create AWS IAM policies and a user to connect to CAST AI.
module "castai-eks-role-iam" {
source = "castai/eks-role-iam/castai"
version = "~> 2.0"
aws_account_id = data.aws_caller_identity.current.account_id
aws_cluster_region = var.cluster_region
aws_cluster_name = var.cluster_name
aws_cluster_vpc_id = module.vpc.vpc_id
castai_user_arn = castai_eks_user_arn.castai_user_arn.arn
create_iam_resources_per_cluster = true
}
# Configure EKS cluster connection using CAST AI eks-cluster module.
resource "castai_eks_clusterid" "cluster_id" {
account_id = data.aws_caller_identity.current.account_id
region = var.cluster_region
cluster_name = var.cluster_name
}
module "castai-eks-cluster" {
source = "castai/eks-cluster/castai"
version = "~> 14.1"
api_url = var.castai_api_url
castai_api_token = var.castai_api_token
grpc_url = var.castai_grpc_url
wait_for_cluster_ready = true
aws_account_id = data.aws_caller_identity.current.account_id
aws_cluster_region = var.cluster_region
aws_cluster_name = module.eks.cluster_name
aws_assume_role_arn = module.castai-eks-role-iam.role_arn
delete_nodes_on_disconnect = var.delete_nodes_on_disconnect
default_node_configuration_name = "default"
node_configurations = {
default = {
subnets = module.vpc.private_subnets
tags = var.tags
security_groups = [
module.eks.cluster_security_group_id,
module.eks.node_security_group_id,
aws_security_group.additional.id,
]
instance_profile_arn = module.castai-eks-role-iam.instance_profile_arn
}
test_node_config = {
subnets = module.vpc.private_subnets
tags = var.tags
security_groups = [
module.eks.cluster_security_group_id,
module.eks.node_security_group_id,
aws_security_group.additional.id,
]
instance_profile_arn = module.castai-eks-role-iam.instance_profile_arn
kubelet_config = jsonencode({
"registryBurst" : 20,
"registryPullQPS" : 10
})
container_runtime = "containerd"
volume_type = "gp3"
volume_iops = 3100
volume_throughput = 130
imds_v1 = true
}
}
node_templates = {
default_by_castai = {
name = "default-by-castai"
configuration_name = "default"
is_default = true
is_enabled = true
should_taint = false
constraints = {
on_demand = true
spot = true
use_spot_fallbacks = true
enable_spot_diversity = false
spot_diversity_price_increase_limit_percent = 20
spot_interruption_predictions_enabled = true
spot_interruption_predictions_type = "aws-rebalance-recommendations"
}
}
spot_tmpl = {
configuration_name = "default"
is_enabled = true
should_taint = true
custom_labels = {
custom-label-key-1 = "custom-label-value-1"
custom-label-key-2 = "custom-label-value-2"
}
custom_taints = [
{
key = "custom-taint-key-1"
value = "custom-taint-value-1"
},
{
key = "custom-taint-key-2"
value = "custom-taint-value-2"
}
]
constraints = {
fallback_restore_rate_seconds = 1800
spot = true
use_spot_fallbacks = true
min_cpu = 4
max_cpu = 100
instance_families = {
exclude = ["m5"]
}
compute_optimized_state = "disabled"
storage_optimized_state = "disabled"
is_gpu_only = false
# Optional: define custom priority for instances selection.
#
# 1. Prioritize C5a and C5ad spot instances above all else, regardless of price.
# 2. If C5a is not available, try C6a family.
custom_priority = [
{
instance_families = ["c5a", "c5ad"]
spot = true
},
{
instance_families = ["c6a"]
spot = true
}
# 3. instances not matching any of custom priority groups will be tried after
# nothing matches from priority groups.
]
}
}
}
autoscaler_settings = {
enabled = true
is_scoped_mode = false
node_templates_partial_matching_enabled = false
unschedulable_pods = {
enabled = true
}
node_downscaler = {
enabled = true
empty_nodes = {
enabled = true
}
evictor = {
aggressive_mode = false
cycle_interval = "5m10s"
dry_run = false
enabled = true
node_grace_period_minutes = 10
scoped_mode = false
}
}
cluster_limits = {
enabled = true
cpu = {
max_cores = 20
min_cores = 1
}
}
}
# depends_on helps Terraform with creating proper dependencies graph in case of resource creation and in this case destroy.
# module "castai-eks-cluster" has to be destroyed before module "castai-eks-role-iam".
depends_on = [module.castai-eks-role-iam, module.vpc, module.eks]
}