2023-05-03 14:52:20 +02:00
|
|
|
resource "google_container_cluster" "primary" {
|
|
|
|
name = "${var.project}-gke"
|
2024-06-16 10:41:35 +02:00
|
|
|
location = var.zone
|
2023-05-03 14:52:20 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2024-05-05 12:06:11 +02:00
|
|
|
network = google_compute_network.vpc.name
|
|
|
|
subnetwork = google_compute_subnetwork.subnet.name
|
|
|
|
deletion_protection = false # Use this only for study purposess
|
|
|
|
depends_on = [google_compute_network.vpc, google_compute_subnetwork.subnet]
|
2023-05-03 14:52:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "primary_nodes" {
|
|
|
|
name = google_container_cluster.primary.name
|
2024-06-16 10:41:35 +02:00
|
|
|
location = var.zone
|
2023-05-03 14:52:20 +02:00
|
|
|
cluster = google_container_cluster.primary.name
|
2024-06-16 10:41:35 +02:00
|
|
|
node_count = 1
|
2023-05-03 14:52:20 +02:00
|
|
|
|
|
|
|
node_config {
|
|
|
|
oauth_scopes = [
|
2024-06-16 10:41:35 +02:00
|
|
|
"https://www.googleapis.com/auth/cloud-platform",
|
|
|
|
"https://www.googleapis.com/auth/compute",
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
2023-05-03 14:52:20 +02:00
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring",
|
|
|
|
]
|
|
|
|
|
|
|
|
labels = {
|
|
|
|
env = var.project
|
|
|
|
}
|
|
|
|
|
|
|
|
preemptible = true
|
2024-06-16 10:41:35 +02:00
|
|
|
machine_type = "n2-standard-8"
|
|
|
|
tags = [
|
|
|
|
"${var.environment_name}-k8s-${var.region}",
|
|
|
|
"${var.environment_name}-k8s-${var.region}-nodes"
|
|
|
|
]
|
2023-05-03 14:52:20 +02:00
|
|
|
metadata = {
|
|
|
|
disable-legacy-endpoints = "true"
|
|
|
|
}
|
|
|
|
}
|
2024-05-05 12:06:11 +02:00
|
|
|
|
|
|
|
depends_on = [google_container_cluster.primary]
|
2023-05-03 14:52:20 +02:00
|
|
|
}
|