Create a standardized GKE cluster that is good enough for a bunch of general purpose work.
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
}
}
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({ |
{ |
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({ |
[] |
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 |
Name | Description |
---|---|
ca_certificate | Kubernetes cluster CA certificate |
configure_kubectl | Command to configure credentials for kubectl |
endpoint | Kubernetes endpoint |