When using the Terraform CLI, make sure you have all the necessary tools installed on your workstation.
Prepare a file with authentication information, as described in Authenticating Terraform to access Google Cloud.
Prepare your terraform.tfvars
file, as described in Customize Input Values.
Initialize the Terraform environment for this project by running
terraform init
This creates a .terraform
directory locally and initializes Terraform plugins and modules used in this project.
Note: terraform init
only needs to be run once unless new Terraform plugins or modules were added.
To preview the resources that the Terraform script will create, run
terraform plan
When satisfied with the plan and ready to create cloud resources, run
terraform apply -auto-approve
This command can take a few minutes to complete. Once complete, Terraform output values are written to the console.
The kubeconfig file for the cluster is being written to [prefix]-gke-kubeconfig.conf
in the current directory $(pwd)
.
Once the cloud resources have been created with apply
command, to display Terraform output values, run
terraform output
After provisioning the infrastructure, if further changes were to be made then add the variable and desired value to terraform.tfvars
and run terrafom apply
again.
To destroy the kubernetes cluster and all related resources, run
terraform destroy
NOTE: The "destroy" action is irreversible.
Creating the cloud resources writes the kube_config
output value to a file ./[prefix]-gke-kubeconfig.conf
. When the Kubernetes cluster is ready, use kubectl
to interact with the cluster.
Note this requires cluster_endpoint_public_access_cidrs
value to be set to your local ip or CIDR range.
export KUBECONFIG=$(pwd)/<your prefix>-gke-kubeconfig.conf
kubectl get nodes