-
Notifications
You must be signed in to change notification settings - Fork 135
/
main.tf
212 lines (180 loc) · 5.01 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
#
# Provider configuration
#
provider "google" {
credentials = file(".gcloud-credentials.json")
project = var.project
region = var.region
zone = var.zone
version = "~> 3.19"
}
# Pull Access Token from gcloud client config
# See: https://www.terraform.io/docs/providers/google/d/datasource_client_config.html
data "google_client_config" "gcloud" {}
provider "kubernetes" {
load_config_file = false
host = google_container_cluster.cluster.endpoint
# Use the token to authenticate to K8s
token = data.google_client_config.gcloud.access_token
cluster_ca_certificate = base64decode(google_container_cluster.cluster.master_auth[0].cluster_ca_certificate)
}
#
# Kubernetes cluster
#
resource "google_container_cluster" "cluster" {
name = var.indexer
# We can't create a cluster with no node pool defined, but we want to only use
# separately managed node pools. So we create the smallest possible default
# node pool and immediately delete it.
remove_default_node_pool = true
initial_node_count = 1
release_channel {
channel = var.release_channel
}
network = "projects/${var.project}/global/networks/default"
master_auth {
username = ""
password = ""
client_certificate_config {
issue_client_certificate = false
}
}
ip_allocation_policy {
// Enable IP aliases, but let GKE choose all the values
}
}
resource "google_container_node_pool" "default_pool" {
name = "default-pool"
cluster = google_container_cluster.cluster.name
node_count = var.sizes.default_pool
node_config {
preemptible = var.preemptible
machine_type = var.default_machine_type
image_type = var.image_type
shielded_instance_config {
enable_secure_boot = var.secure_boot
}
metadata = {
disable-legacy-endpoints = "true"
}
oauth_scopes = [
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/trace.append"
]
}
}
resource "google_container_node_pool" "query_pool" {
name = "query-pool"
cluster = google_container_cluster.cluster.name
node_count = var.sizes.query_pool
node_config {
preemptible = var.preemptible
machine_type = var.machine_type
image_type = var.image_type
shielded_instance_config {
enable_secure_boot = var.secure_boot
}
metadata = {
disable-legacy-endpoints = "true"
}
labels = {
query = "1"
}
taint = [
{
effect = "NO_SCHEDULE"
key = "query"
value = "1"
},
]
oauth_scopes = [
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/trace.append"
]
}
}
resource "google_container_node_pool" "index_pool" {
name = "index-pool"
cluster = google_container_cluster.cluster.name
node_count = var.sizes.index_pool
node_config {
preemptible = var.preemptible
machine_type = var.machine_type
image_type = var.image_type
shielded_instance_config {
enable_secure_boot = var.secure_boot
}
metadata = {
disable-legacy-endpoints = "true"
}
labels = {
index = "1"
}
taint = [
{
effect = "NO_SCHEDULE"
key = "index"
value = "1"
},
]
oauth_scopes = [
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/trace.append"
]
}
}
resource "google_compute_disk" "nfs" {
name = "${var.indexer}-nfs"
type = "pd-standard"
size = 256
}
resource "kubernetes_persistent_volume" "nfs" {
metadata {
name = "nfs"
}
spec {
capacity = {
storage = "256Gi"
}
access_modes = ["ReadWriteOnce"]
persistent_volume_source {
gce_persistent_disk {
pd_name = google_compute_disk.nfs.name
fs_type = "ext4"
}
}
storage_class_name = "standard"
}
}
resource "kubernetes_persistent_volume_claim" "nfs" {
metadata {
name = "nfs"
}
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = "256Gi"
}
}
selector {
match_labels = {
"name" = kubernetes_persistent_volume.nfs.metadata.0.name
}
}
storage_class_name = "standard"
volume_name = kubernetes_persistent_volume.nfs.metadata.0.name
}
}