/
main.tf
274 lines (243 loc) · 8.4 KB
/
main.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# configure cloud storage backend to keep state information. This is shared
# across all users and contains the previously configured parts. Accessing
# GCS requires that the environment variable `GOOGLE_CLOUD_KEYFILE_JSON` points
# to your credential file, e.g.
# ~/.config/gcloud/legacy_credentials/<your email>/adc.json
terraform {
backend "gcs" {
bucket = "buildbot_cluster_terraform_backend"
prefix = "terraform/state"
}
}
# configure Google Cloud project
provider "google" {
project = var.gcp_config.project
region = var.gcp_config.region
}
# create a network for the cluster, required for Kubernetes on Windows
# FIXME: rename to "buildbot-vpc-network", causes destruction of the cluster!
resource "google_compute_network" "vpc_network" {
name = "vpc-network"
}
# Create the cluster runningn all Kubernetes services
resource "google_container_cluster" "primary" {
name = "buildbot-cluster"
# maybe have a regional cluster for Kubernetes, as we depend on this...
location = var.gcp_config.zone_a
# configure local network, required for Kubernetes on Windows
network = google_compute_network.vpc_network.name
# enable alias IP addresses, required for Kubernetes for Windows
ip_allocation_policy {}
# use newer Kubernetes version, otherwise Windows node pools can't be created
min_master_version = "1.16"
# one node is enough (at the moment)
initial_node_count = 1
node_config {
# FIXME(kuhnel): turn this into a private cluster, without external IP
# We need at least 2 vCPU to run all kubernetes services
machine_type = "e2-medium"
# use preemptible, as this saves costs
preemptible = true
}
}
resource "null_resource" "update_cluster" {
# Add NVIDIA driver daemonset.
depends_on = [google_container_cluster.primary]
# Update kubectl context for the cluster and apply nvidia's daemonset.
provisioner "local-exec" {
command = <<EOT
gcloud container clusters get-credentials cudabot
kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators/master/nvidia-driver-installer/cos/daemonset-preloaded.yaml
EOT
}
}
# Create machines for mlir-nvidia
# Note: The buildbot mlir-nividia is deployed using a kubernetes file. See
# the README.md for details on GPUs.
resource "google_container_node_pool" "nvidia_16core_pool_nodes" {
name = "nvidia-16core-pool"
# specify a zone here (e.g. "-a") to avoid a redundant deployment
location = var.gcp_config.zone_a
cluster = google_container_cluster.primary.name
# use autoscaling to only create a machine when there is a deployment
autoscaling {
min_node_count = 0
max_node_count = 2
}
node_config {
# use preemptible, as this saves costs
preemptible = true
# FIXME upgrade to "n1-custom-24-32768"
machine_type = "n1-highcpu-16"
disk_size_gb = 100
# FIXME: test if SSDs are actually faster than HDDs for our use case
disk_type = "pd-ssd"
guest_accelerator {
type = "nvidia-tesla-t4"
count= 1
}
# set the premissions required for the deployment later
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/devstorage.read_only",
]
# add a label to all machines of this type, so we can select them
# during deployment
labels = {
pool = "nvidia-16core-pool"
}
}
}
resource "null_resource" "deployment-mlir-nvidia" {
# Add NVIDIA driver daemonset.
depends_on = [null_resource.update_cluster]
triggers = {
t4_contents = filemd5("${path.module}/deployment-mlir-nvidia-production.yaml")
}
# Add NVIDIA daemonset and deploy mlir-nvidia.
# Using this workaround as terraform does not support GPUs on Google Cloud.
# https://github.com/terraform-providers/terraform-provider-kubernetes/issues/149
provisioner "local-exec" {
command = "kubectl apply -f ${path.module}/deployment-mlir-nvidia-production.yaml"
}
}
# node pool for windows machines
resource "google_container_node_pool" "windows_32core_pool_nodes" {
name = "windows-32core-pool"
# specify a zone here (e.g. "-a") to avoid a redundant deployment
location = var.gcp_config.zone_a
cluster = google_container_cluster.primary.name
# use autoscaling to only create a machine when there is a deployment
autoscaling {
min_node_count = 0
max_node_count = 1
}
node_config {
# use preemptible, as this saves costs
preemptible = true
machine_type = "e2-highcpu-32"
# Windows deployments tend to require more disk space, so using 300GB here.
disk_size_gb = 300
# FIXME: test if SSDs are actually faster than HDDs for our use case
disk_type = "pd-ssd"
# Configure Windows image. As Windows is picky about the combination of
# host and container OS versions, this must be compatible with the version
# in your container. Recommondation: Use LTSC for long-term stability.
# For details see
# https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility
# https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster-windows#choose_your_windows_server_node_image
image_type = "WINDOWS_LTSC"
# set the premissions required for the deployment later
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/devstorage.read_only",
]
# add a label to all machines of this type, so we can select them
# during deployment
labels = {
pool = "win-32core-pool"
}
}
}
# Deployment for the buildbot windows10_vs2019 running on Windows rather than
# Linux.
# Note: Deploying this takes significantly longer (~35 min) than on Linux
# as the images tend to be larger (~18GB) and IO performance is lower.
resource "kubernetes_deployment" "windows10_vs2019" {
metadata {
name = "windows10-vs2019"
labels = {
app = "windows10_vs2019"
}
}
spec {
# create one instance of this container
replicas = 1
selector {
match_labels = {
app = "windows10_vs2019"
}
}
strategy{
rolling_update{
# do not deploy more replicas, as the buildbot server
# can't handle multiple workers with the same credentials
max_surge = 0
# Allow to have 0 replicas during updates.
max_unavailable = 1
}
type = "RollingUpdate"
}
template {
metadata {
labels = {
app = "windows10_vs2019"
}
}
spec {
container {
image = "${var.gcp_config.gcr_prefix}/buildbot-windows10-vs2019:17"
name = "windows10-vs2019"
# reserve "<number of cores>-1" for this image, kubernetes also
# needs <1 core for management tools
resources {
limits {
cpu = "31"
memory = "20Gi"
}
requests {
cpu = "31"
memory = "20Gi"
}
}
# mount the secrets into a folder
volume_mount {
mount_path = "c:\\volumes\\secrets"
name = "buildbot-token"
}
volume_mount {
mount_path = "c:\\volumes\\sccache"
name = "sccache-vol"
}
volume_mount {
mount_path = "c:\\volumes\\buildbot"
name = "buildbot-vol"
}
}
# select which node pool to deploy to
node_selector = {
pool = "win-32core-pool"
}
# restart in case of any crashes
restart_policy = "Always"
# select the secret to be mounted
volume {
name = "buildbot-token"
secret {
optional = false
secret_name = "password-windows10-vs2019"
}
}
volume {
name = "sccache-vol"
empty_dir {}
}
volume {
name = "buildbot-vol"
empty_dir {}
}
# Windows nodes from the node pool are marked with the taint
# "node.kubernetes.io/os=windows". So we need to "tolerate" this to
# deploy to such nodes.
toleration {
effect = "NoSchedule"
key = "node.kubernetes.io/os"
operator = "Equal"
value = "windows"
}
}
}
}
}