Skip to content

infrastructure-as-code/terraform-google-gke-cluster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Cloud GKE Cluster

Introduction

Create a standardized GKE cluster that is good enough for a bunch of general purpose work.

Usage

The most basic way to create a GKE cluster using the Terraform google_container_cluster resource with worker nodes in the default pool.

provider "google-beta" {
  region = "us-central1"
  zone   = "us-central1-a"
  alias  = "google_beta"
}

locals {
  container_cluster_name = "k8s-1"
  container_cluster_zone = "us-central1-a"
  k8s_version            = "1.14.10-gke.22"
  cluster_type           = "zonal"
  project_id             = "a-project-id"
}

module "gke" {
  source       = "github.com/infrastructure-as-code/terraform-google-gke-cluster"
  name         = local.container_cluster_name
  location     = local.container_cluster_zone
  cluster_type = local.cluster_type
  k8s_version  = local.k8s_version
  project_id   = local.project_id

  remove_default_node_pool = false
  default_node_pool = {
      machine_type = "e2-standard-2"
      disk_type    = "pd-standard"
      disk_size_gb = 100
      preemptible  = true
      count        = 3
  }

  providers = {
    google = google-beta.google_beta
  }
}

Setting the remove_default_node_pool variable to true will remove the default node pool, and create additional pools of workers as defined by the node_pools variable.

provider "google-beta" {
  region = "us-central1"
  zone   = "us-central1-a"
  alias  = "google_beta"
}

locals {
  container_cluster_name = "k8s-1"
  container_cluster_zone = "us-central1-a"
  k8s_version            = "1.14.10-gke.22"
  cluster_type           = "zonal"
  project_id             = "a-project-id"
}

module "gke" {
  source       = "github.com/infrastructure-as-code/terraform-google-gke-cluster"
  name         = local.container_cluster_name
  location     = local.container_cluster_zone
  cluster_type = local.cluster_type
  k8s_version  = local.k8s_version
  project_id   = local.project_id

  remove_default_node_pool = true
  node_pools = [
    {
      name         = "main-pool"
      machine_type = "e2-standard-2"
      disk_type    = "pd-standard"
      disk_size_gb = 100
      preemptible  = true
      count        = 3
    },
  ]

  providers = {
    google = google-beta.google_beta
  }
}

Inputs

Name Description Type Default Required
cluster_type regional or zonal cluster string n/a yes
default_node_pool Nodes in the default node pool
object({
machine_type = string
disk_type = string
disk_size_gb = number
preemptible = bool
count = number
})
{
"count": 3,
"disk_size_gb": 20,
"disk_type": "pd-standard",
"machine_type": "f1-micro",
"preemptible": false
}
no
k8s_version Kubernetes version string n/a yes
location Cluster region or zone string n/a yes
name Name of cluster string n/a yes
node_pools Type of nodes and number for each
list(object({
name = string
machine_type = string
disk_type = string
disk_size_gb = number
preemptible = bool
count = number
}))
[] no
project_id Project ID string n/a yes
remove_default_node_pool Delete the default node pool after the cluster is created bool false no

Outputs

Name Description
ca_certificate Kubernetes cluster CA certificate
configure_kubectl Command to configure credentials for kubectl
endpoint Kubernetes endpoint

References

  1. https://www.terraform.io/docs/providers/google/r/container_cluster.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published