-
Notifications
You must be signed in to change notification settings - Fork 1
/
gke-cluster.tf
284 lines (217 loc) · 9.25 KB
/
gke-cluster.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
275
276
277
278
279
280
281
282
283
resource "google_container_cluster" "google_container_cluster" {
project = var.project_name
name = format("%s-cluster", var.cluster_name)
initial_node_count = var.initial_node_count
min_master_version = data.google_container_engine_versions.cluster_engine_version.latest_master_version
network = google_compute_network.vpc_network.name
subnetwork = google_compute_subnetwork.network-with-private-secondary-ip-ranges.name
remove_default_node_pool = true
logging_service = var.logging_service
monitoring_service = var.monitoring_service
location = var.location_zone
private_cluster_config {
enable_private_nodes = true
enable_private_endpoint = true
master_ipv4_cidr_block = "172.16.0.16/28"
}
ip_allocation_policy {
#cluster_ipv4_cidr_block = google_compute_subnetwork.network-with-private-secondary-ip-ranges.secondary_ip_range.0.ip_cidr_range
#services_ipv4_cidr_block = google_compute_subnetwork.network-with-private-secondary-ip-ranges.secondary_ip_range.1.ip_cidr_range
cluster_secondary_range_name = google_compute_subnetwork.network-with-private-secondary-ip-ranges.secondary_ip_range.0.range_name
services_secondary_range_name = google_compute_subnetwork.network-with-private-secondary-ip-ranges.secondary_ip_range.1.range_name
}
enable_legacy_abac = true
master_authorized_networks_config {
dynamic "cidr_blocks" {
for_each = var.master_authorized_networks_config
content {
cidr_block = cidr_blocks.value.cidr_block
display_name = lookup(cidr_blocks.value, "display_name", null)
}
}
}
master_auth {
username = var.cluster_master_username
password = var.cluster_master_password
client_certificate_config {
issue_client_certificate = false
}
}
addons_config {
http_load_balancing {
disabled = var.http_load_balancing
}
}
depends_on = [data.google_container_engine_versions.cluster_engine_version]
}
resource "google_container_node_pool" "primary_preemptible_nodes" {
name = var.node_pool_name
location = var.location_zone
cluster = google_container_cluster.google_container_cluster.name
node_config {
preemptible = var.preemptible
machine_type = var.node_machine_type
disk_size_gb = var.node_disk_size_gb
disk_type = var.node_disk_type
tags = var.node_tags
oauth_scopes = var.oauth_scopes
image_type = var.os_image_type
service_account = google_service_account.trusted_zone_cluster_sa.email
metadata = {
disable-legacy-endpoints = "true"
}
}
initial_node_count = var.initial_node_count
#autoscaling {
# min_node_count = var.min_node_count
# max_node_count = var.max_node_count
#}
management {
auto_repair = "true"
auto_upgrade = "true"
}
depends_on = [google_container_cluster.google_container_cluster]
#provisioner "local-exec" {
# command = "gcloud container clusters get-credentials ${google_container_cluster.google_container_cluster.name} --zone ${google_container_cluster.google_container_cluster.location} --project ${google_container_cluster.google_container_cluster.project}"
# }
###Tainting one Worker node and Labelling
##provisioner "local-exec" {
# command = "kubectl taint node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server:NoSchedule"
#}
##provisioner "local-exec" {
# command = "kubectl label node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server"
#}
}
resource "google_container_node_pool" "primary_preemptible_nodes-agents-1" {
name = var.node_pool_name_second
location = var.location_zone
cluster = google_container_cluster.google_container_cluster.name
node_config {
preemptible = var.preemptible
machine_type = var.node_machine_type_agent
disk_size_gb = var.node_disk_size_gb
disk_type = var.node_disk_type
tags = var.node_tags
oauth_scopes = var.oauth_scopes
image_type = var.os_image_type
service_account = google_service_account.trusted_zone_cluster_sa.email
taint = [{
effect = "NO_SCHEDULE"
key = "servertype"
value = "teamcity-agent-1"
}]
metadata = {
disable-legacy-endpoints = "true"
}
}
initial_node_count = var.initial_node_count_agent
#autoscaling {
# min_node_count = var.min_node_count
# max_node_count = var.max_node_count
#}
management {
auto_repair = "true"
auto_upgrade = "true"
}
depends_on = [google_container_cluster.google_container_cluster]
# provisioner "local-exec" {
# command = "gcloud container clusters get-credentials ${google_container_cluster.google_container_cluster.name} --zone ${google_container_cluster.google_container_cluster.location} --project ${google_container_cluster.google_container_cluster.project}"
# }
###Tainting one Worker node and Labelling
##provisioner "local-exec" {
# command = "kubectl taint node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server:NoSchedule"
#}
##provisioner "local-exec" {
# command = "kubectl label node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server"
#}
}
# kubectl taint node $(kubectl get nodes | grep agent |awk 'NR==1{print $1; exit}') servertype=teamcity-agents:NoSchedule
# kubectl taint node $(kubectl get nodes | grep agent |awk 'NR==2{print $1; exit}') servertype=teamcity-agent-3:NoSchedule
# kubectl label node $(kubectl get nodes | grep agent |awk 'NR==1{print $1; exit}') servertype=teamcity-agents
# kubectl label node $(kubectl get nodes | grep agent |awk 'NR==2{print $1; exit}') servertype=teamcity-agent-3
resource "google_container_node_pool" "primary_preemptible_nodes-agents-2" {
name = var.node_pool_name_third
location = var.location_zone
cluster = google_container_cluster.google_container_cluster.name
node_config {
preemptible = var.preemptible
machine_type = var.node_machine_type_agent
disk_size_gb = var.node_disk_size_gb
disk_type = var.node_disk_type
tags = var.node_tags
oauth_scopes = var.oauth_scopes
image_type = var.os_image_type
service_account = google_service_account.trusted_zone_cluster_sa.email
taint = [{
effect = "NO_SCHEDULE"
key = "servertype"
value = "teamcity-agent-2"
}]
metadata = {
disable-legacy-endpoints = "true"
}
}
initial_node_count = var.initial_node_count_agent
#autoscaling {
# min_node_count = var.min_node_count
# max_node_count = var.max_node_count
#}
management {
auto_repair = "true"
auto_upgrade = "true"
}
depends_on = [google_container_cluster.google_container_cluster]
# provisioner "local-exec" {
# command = "gcloud container clusters get-credentials ${google_container_cluster.google_container_cluster.name} --zone ${google_container_cluster.google_container_cluster.location} --project ${google_container_cluster.google_container_cluster.project}"
# }
###Tainting one Worker node and Labelling
##provisioner "local-exec" {
# command = "kubectl taint node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server:NoSchedule"
#}
##provisioner "local-exec" {
# command = "kubectl label node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server"
#}
}
resource "google_container_node_pool" "primary_preemptible_nodes-agents-3" {
name = var.node_pool_name_fourth
location = var.location_zone
cluster = google_container_cluster.google_container_cluster.name
node_config {
preemptible = var.preemptible
machine_type = var.node_machine_type_agent
disk_size_gb = var.node_disk_size_gb
disk_type = var.node_disk_type
tags = var.node_tags
oauth_scopes = var.oauth_scopes
image_type = var.os_image_type
service_account = google_service_account.trusted_zone_cluster_sa.email
taint = [{
effect = "NO_SCHEDULE"
key = "servertype"
value = "teamcity-agent-3"
}]
metadata = {
disable-legacy-endpoints = "true"
}
}
initial_node_count = var.initial_node_count_agent
#autoscaling {
# min_node_count = var.min_node_count
# max_node_count = var.max_node_count
#}
management {
auto_repair = "true"
auto_upgrade = "true"
}
depends_on = [google_container_cluster.google_container_cluster]
# provisioner "local-exec" {
# command = "gcloud container clusters get-credentials ${google_container_cluster.google_container_cluster.name} --zone ${google_container_cluster.google_container_cluster.location} --project ${google_container_cluster.google_container_cluster.project}"
# }
###Tainting one Worker node and Labelling
##provisioner "local-exec" {
# command = "kubectl taint node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server:NoSchedule"
#}
##provisioner "local-exec" {
# command = "kubectl label node $(kubectl get nodes | grep addoptify |awk 'NR==1{print $1; exit}') servertype=teamcity-server"
#}
}