-
Notifications
You must be signed in to change notification settings - Fork 0
/
eks.tf
238 lines (204 loc) · 6.34 KB
/
eks.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Gets the latest AWS EKS AMI with GPU support
data "aws_ami" "eks_gpu_ami" {
most_recent = true
filter {
name = "name"
values = ["amazon-eks-gpu-node-${local.cluster_version}-*"]
}
}
# Gets the latest regular AWS EKS AMI
data "aws_ami" "eks_al2_ami" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amazon-eks-node-${local.cluster_version}-*"]
}
filter {
name = "owner-alias"
values = ["amazon"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
}
module "ollama-eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 20.0"
cluster_name = local.cluster_name
cluster_version = local.cluster_version
cluster_endpoint_public_access = true
cluster_addons = {
coredns = {
most_recent = true
resolve_conflicts = "OVERWRITE"
}
kube-proxy = {
most_recent = true
resolve_conflicts = "OVERWRITE"
}
vpc-cni = {
most_recent = true
resolve_conflicts = "OVERWRITE"
}
aws-ebs-csi-driver = {
most_recent = true
resolve_conflicts = "OVERWRITE"
service_account_role_arn = aws_iam_role.ebs_csi_driver_role.arn
}
}
# Networking
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
control_plane_subnet_ids = module.vpc.private_subnets
cluster_security_group_name = "ollama-eks-cluster"
node_security_group_name = "ollama-eks-nodes"
node_security_group_additional_rules = {
alb_ingress = {
description = "Access from Ingress ALBs"
protocol = "tcp"
from_port = 8080
to_port = 8080
type = "ingress"
source_security_group_id = aws_security_group.open-webui-ingress-sg.id
}
}
# EKS Managed Node Groups
eks_managed_node_groups = {
open-webui = {
# Number of instances to deploy
min_size = 1
max_size = 1
desired_size = 1
# AMI and instance type
ami_id = data.aws_ami.eks_al2_ami.id
instance_types = ["m5a.large"]
capacity_type = "ON_DEMAND"
# Adds a disk large enough to store user data and files uploaded for RAG
disk_size = 100
block_device_mappings = {
xvda = {
device_name = "/dev/xvda"
ebs = {
volume_size = 100
volume_type = "gp2"
delete_on_termination = true
}
}
}
# Adds IAM permissions to node role
create_iam_role = true
iam_role_name = "open-webui-eks-node-group"
iam_role_additional_policies = {
AmazonALBIngressController = aws_iam_policy.aws_load_balancer_controller.arn
AmazonSSMManagedInstanceCore = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
AWSExternalDNS = aws_iam_policy.external_dns.arn
}
# User data bootstraps EKS node and installs AWS CLI
pre_bootstrap_user_data = <<-EOT
#!/bin/bash
/etc/eks/bootstrap.sh ${local.cluster_name}
EOT
# Adds Kubernetes labels used for pod placement
node_group_labels = {
"app" = "open-webui"
}
tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "owned"
}
}
ollama-small-fim = {
# Number of instances to deploy
min_size = 1
max_size = 1
desired_size = 1
# AMI and instance type
ami_id = data.aws_ami.eks_gpu_ami.id
instance_types = ["g5.xlarge"]
capacity_type = "ON_DEMAND"
# Adds IAM permissions to node role
create_iam_role = true
iam_role_name = "ollama-fim-eks-node-group"
iam_role_additional_policies = {
AmazonALBIngressController = aws_iam_policy.aws_load_balancer_controller.arn
AmazonSSMManagedInstanceCore = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
AWSExternalDNS = aws_iam_policy.external_dns.arn
}
# Adds a disk large enough to store models
disk_size = 30
block_device_mappings = {
xvda = {
device_name = "/dev/xvda"
ebs = {
volume_size = 30
volume_type = "gp2"
delete_on_termination = true
}
}
}
# User data bootstraps EKS node
pre_bootstrap_user_data = <<-EOT
#!/bin/bash
/etc/eks/bootstrap-gpu-nvidia.sh
/etc/eks/bootstrap.sh ${local.cluster_name}
EOT
tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "owned"
}
# Adds Kubernetes labels used for pod placement
node_group_labels = {
"app" = "ollama"
}
}
ollama-small-chat = {
# Number of instances to deploy
min_size = 1
max_size = 1
desired_size = 1
# AMI and instance type
ami_id = data.aws_ami.eks_gpu_ami.id
instance_types = ["g5.xlarge"]
capacity_type = "ON_DEMAND"
# Adds IAM permissions to node role
create_iam_role = true
iam_role_name = "ollama-chat-eks-node-group"
iam_role_additional_policies = {
AmazonALBIngressController = aws_iam_policy.aws_load_balancer_controller.arn
AmazonSSMManagedInstanceCore = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
AWSExternalDNS = aws_iam_policy.external_dns.arn
}
# Adds a disk large enough to store models
disk_size = 30
block_device_mappings = {
xvda = {
device_name = "/dev/xvda"
ebs = {
volume_size = 30
volume_type = "gp2"
delete_on_termination = true
}
}
}
# User data bootstraps EKS node
pre_bootstrap_user_data = <<-EOT
#!/bin/bash
/etc/eks/bootstrap-gpu-nvidia.sh
/etc/eks/bootstrap.sh ${local.cluster_name}
EOT
tags = {
"kubernetes.io/cluster/${local.cluster_name}" = "owned"
}
# Adds Kubernetes labels used for pod placement
node_group_labels = {
"app" = "ollama"
}
}
}
# To add the current caller identity as an administrator
enable_cluster_creator_admin_permissions = true
}