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 c355d27bb1 refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
.gitignore refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
.pre-commit-config.yaml add gke cluster code 2023-05-03 08:52:20 -04:00
.terraform.lock.hcl refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
README.md refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
demo-namespace.tf refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
get-credentials.sh refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
gke.tf refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
outputs.tf refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
providers.tf refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
variables.tf refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00
versions.tf bump providers; added some outputs 2024-05-05 13:35:15 +04:00
vpc.tf refactor readme and some cluster; add script for fetch cluster creds 2024-06-16 12:41:35 +04:00

README.md

How to use repo

  1. Create terraform.tfvars file with a few variables
project          = "gcp-project"
region           = "europe-west1"
environment_name = "demo"
  1. Create cluster All commands will be applied via Terraform 1.7.0 and via OpenTofu, the same version.

Here are OpenTofu commands.

tofu init
tofu apply
  1. Get the credentials for the new cluster (configure kubeconfig)

You can see all useful commands and links in the output:

tofu output

There is a manual command:

gcloud container clusters get-credentials $(tofu output -raw kubernetes_cluster_name) --region $(tofu output -raw zone) --project $(tofu output -raw project)

Or just use ./get-credentials.sh

  1. Destroy all resources
tofu destroy

Requirements

Name Version
terraform ~>1.7.0
google ~>5.27.0
kubernetes ~>2.29.0

Providers

Name Version
google 5.27.0
kubernetes 2.29.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
google_project_service.service_networking resource
kubernetes_namespace.demo-cluster resource
google_client_config.primary data source

Inputs

Name Description Type Default Required
environment_name n/a string "demo" 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
zone The region to host the cluster in string "us-central1-b" no

Outputs

Name Description
gcloud_gke_get_creds Command to get GKE credentials
gcloud_gke_link GKE web ui link
gcloud_vpc_link VPC web ui link
kubernetes_cluster_host GKE Cluster Host
kubernetes_cluster_name GKE Cluster Name
project GCloud Project ID
region GCloud Region
zone GCloud Project ID