This repository showcases using Terraform to provision a new network and a GKE cluster with nodes within.
By default, this will create a highly available cluster using a NAT gateway for outgoing traffic from private nodes.
See a high level overview of the GKE architecture.
Ensure that kubectl
, gcloud
, and terraform
are installed first.
Ensure the Google Cloud CLI tools are initalised:
gcloud init
Once initialised, ensure your account is added to the Application Default Credentials (ADC) so Terraform can access them:
gcloud auth application-default login
In terraform.tfvars
set the details according to your Google Cloud account.
project_id
, location
, and name
are required to be set.
location
can be set to a region or zone. See regional or zone specific cluster docs for more information.
An example terraform.tfvars
file of using a single zone cluster with preemptible nodes:
project_id = "my-project-123"
location = "australia-southeast1-a"
name = "mycluster"
node_type = "n1-standard-1"
node_disk_type = "pd-standard"
node_disk_size_gb = 40
node_preemptible = true
initial_node_count = 1
min_node_count = 1
max_node_count = 2
Check out a list of Google Cloud regions and zones for reference.
terraform init
terraform apply
Retrieve the cluster name and location using terraform show
, then initialise kubectl
configuration:
gcloud container clusters get-credentials mycluster --region australia-southeast1-a
kubectl get nodes -o wide
terraform destroy
Check out google_container_cluster
Terraform docs
for more details on what GKE parameters can be changed using Terraform.
Some other things: