Skip to content

Instantly share code, notes, and snippets.

@iamdejan
Created May 26, 2022 06:46
Show Gist options
  • Save iamdejan/952cfa0f3cc0ae02c2fd02d9f354bb02 to your computer and use it in GitHub Desktop.
Save iamdejan/952cfa0f3cc0ae02c2fd02d9f354bb02 to your computer and use it in GitHub Desktop.
GKE cluster provisioning
# GKE cluster
resource "google_container_cluster" "primary" {
name = "${var.project_id}-gke"
location = var.region
# 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
network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.subnet.name
ip_allocation_policy {
cluster_ipv4_cidr_block = local.pods_cidr_range
services_ipv4_cidr_block = local.services_cidr_range
}
}
# Separately Managed Node Pool
resource "google_container_node_pool" "primary_nodes" {
name = "${google_container_cluster.primary.name}-node-pool"
location = var.region
cluster = google_container_cluster.primary.name
node_count = local.gke_num_nodes
node_config {
oauth_scopes = [
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
labels = {
env = var.project_id
}
preemptible = true
machine_type = "e2-micro"
tags = ["gke-node", "${var.project_id}-gke"]
metadata = {
disable-legacy-endpoints = "true"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment