This is a repository with a few examples of GKE clusters that you can create in your own GCP project
Go to file
Aleksei Krugliak 2598cc76d7 add gke cluster code 2023-05-03 08:52:20 -04:00
.gitignore add gke cluster code 2023-05-03 08:52:20 -04:00
.pre-commit-config.yaml add gke cluster code 2023-05-03 08:52:20 -04:00
README.md add gke cluster code 2023-05-03 08:52:20 -04:00
flux.tf add gke cluster code 2023-05-03 08:52:20 -04:00
gke.tf add gke cluster code 2023-05-03 08:52:20 -04:00
outputs.tf add gke cluster code 2023-05-03 08:52:20 -04:00
providers.tf add gke cluster code 2023-05-03 08:52:20 -04:00
variables.tf add gke cluster code 2023-05-03 08:52:20 -04:00
versions.tf add gke cluster code 2023-05-03 08:52:20 -04:00
vpc.tf add gke cluster code 2023-05-03 08:52:20 -04:00

README.md

How to use

  1. Create *.tfvars file with a few variables
project          = "gcp-project"
region           = "europe-west1"
environment_name = "demo"
  1. Create cluster
terraform init
terraform apply
  1. Configure kubeconfig for new cluster
gcloud container clusters get-credentials $(terraform output -raw kubernetes_cluster_name) --region $(terraform output -raw region) --project $(terraform output -raw project)
  1. Destroy all resources
terraform destroy -target 'kubernetes_namespace.flux-system'
terraform destroy -target 'google_container_node_pool.primary_nodes'
terraform destroy -target 'google_container_cluster.primary'
terraform destroy -target 'google_compute_subnetwork.subnet'
terraform destroy -target 'google_compute_network.vpc'
terraform destroy -target 'data.google_client_config.primary'

Requirements

Name Version
terraform ~>1.4.2
google ~>4.62.0
kubernetes ~>2.19.0

Providers

Name Version
google 4.62.1
kubernetes 2.19.0

Modules

No modules.

Resources

Name Type
google_compute_network.vpc resource
google_compute_subnetwork.subnet resource
google_container_cluster.primary resource
google_container_node_pool.primary_nodes resource
kubernetes_namespace.flux-system resource
google_client_config.primary data source

Inputs

Name Description Type Default Required
environment_name n/a string "demo" no
gke_num_nodes number of gke nodes number 1 no
project Google Project to create resources in string "demo" no
region The region to host the cluster in string "us-central1" no
vpc_host_project Host Project where virtual network exists string "demo" no

Outputs

Name Description
kubernetes_cluster_host GKE Cluster Host
kubernetes_cluster_name GKE Cluster Name
project GCloud Project ID
region GCloud Region