In this Article I will show about how to create GKE Cluster with Terraform
Objective
- Create GKE cluster
- Access GKE Cluster
Create GKE cluster
you can create GKE Cluster with GUI. but in this example I will use terraform to create GKE Cluster
git clone https://github.com/dounpct/terraform-gke-test.git
- edit terraform.tfvars for your project and gke information
project_id = "project-test"
region = "asia-southeast1"
zone = "asia-southeast1-a"
cluster_name = "terraform-cluster-01"
vpc_name = "project-test-terraform-cluster-01-vpc"
vpc_subnet_name = "project-test-terraform-cluster-01-subnet"
vpc_subnet_range = "10.10.0.0/24"
machine_type = "n1-standard-2"
gke_num_nodes = 3
- set terraform backend in versions.tf in this example I keep state in GCS (google cloud storage). if you would like to keep state in you local machine. you can remove backend
terraform {
backend "gcs" {
bucket = "gcp-dmp-devops-terraform-state"
prefix = "jiw-terraform-state/terraform-cluster-01"
}
}
# authen gcp
export GOOGLE_APPLICATION_CREDENTIALS="path-to-your-google-service-account-key/key.json"
# apply terraform
terraform init
terraform apply
Access GKE Cluster
- copy Command-line access
- paste in you terminal
gcloud container clusters get-credentials terraform-cluster-01 --zone asia-southeast1-a --project project-test
kubectl get nodes -o wide
— — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Credit : TrueDigitalGroup
— — — — — — — — — — — — — — — — — — — — — — — — — — — — —