Skip to content

buildstar-online/modules-gcp-tf-gke

Repository files navigation

modules-gcp-tf-gke (WiP)

GKE cluster with GPU Nodes

resource "google_container_cluster" "container_cluster" {
  provider                 = google-beta
  name                     = var.cluster_name
  location                 = var.region
  network                  = var.vpc_network_name
  subnetwork               = var.vpc_network_subnet_name
  remove_default_node_pool = true
  initial_node_count       = var.initial_node_count

  node_locations = [
    "europe-west4-a"
//    "europe-west4-b",
//    "europe-west4-c"
  ]
}

resource "google_container_node_pool" "primary_preemptible_nodes" {
  name       = "my-node-pool"
  location   = var.region
  cluster    = google_container_cluster.container_cluster.name
  node_count = 1

  node_config {
    spot         = true
    image_type   = "ubuntu_containerd"
    machine_type = var.machine_type
    disk_type    = var.disk_type
    disk_size_gb = 32
    service_account = var.node_service_account
    oauth_scopes    = [
      "https://www.googleapis.com/auth/cloud-platform"
    ]
    guest_accelerator {
      type  = "nvidia-tesla-t4"
      count = 1
      }
    }

  autoscaling {
    total_min_node_count = 1
    total_max_node_count = 1
    location_policy = var.autoscaling_strategy
  }
}

output "endpoint" {
  value = google_container_cluster.container_cluster.endpoint
}

Connecting to your cluster

  • get your kubeconfig from gcloud

    gcloud container clusters get-credentials <cluster-name> --zone=<your zone>

Requirements

Name Version
helm 2.9.0
kubernetes 2.20.0

Providers

Name Version
google n/a
google-beta n/a
helm 2.9.0

Modules

No modules.

Resources

Name Type
google-beta_google_container_cluster.container_cluster resource
google_container_node_pool.primary_preemptible_nodes resource
helm_release.nginx_ingress resource
google_client_config.client_config data source
google_client_config.provider data source
google_compute_network.network data source
google_compute_subnetwork.network-with-private-secondary-ip-ranges data source

Inputs

Name Description Type Default Required
autoscaling_enabled set autoscaling true or false bool false no
autoscaling_max_nodes max number of nodes allowed number 1 no
autoscaling_min_nodes min number of nodes allocation number 1 no
autoscaling_strategy GKE autoscaling strategy string n/a yes
cluster_name Name of the GKE cluster we will create string n/a yes
disk_size Default size of the node Disk string n/a yes
disk_type 'pd-standard', 'pd-balanced' or 'pd-ssd' string n/a yes
guest_accelerator GPU or TPU to attach to the virtual-machine. string n/a yes
guest_accelerator_count Number of accelerators to attach to each machine number n/a yes
initial_node_count Number of nodes the GKE cluster starts with number 1 no
machine_type The virtual amchine type to use for the node pool string n/a yes
main_availability_zone the gcp region we do all of this in string n/a yes
node_service_account The SA we will use to control nodes on the GKE cluster string n/a yes
project_id GCP project id (gcloud projects list) string n/a yes
region the gcp region we do all of this in string n/a yes
state_bucket_name the name of the bucker we are going to store our state in string n/a yes
state_path directory where we store state string n/a yes
use_default_node_pool True=use the deafult GKE node pool, Fale=use seprately managed pool bool n/a yes
vpc_network_name name of the VPC network our machines will live in string n/a yes
vpc_network_subnet_name name of the VPC subnetwork our machines will live in string n/a yes

Outputs

Name Description
endpoint n/a