Building GKE with Terraform

Provision Google Kubernetes Engine with Terraform

About Terraform

Previous Article


Provisioning GKE with Terraform

Create Project File Structure

mkdir $HOME/gke_project
cd $HOME/gke_project

Initializing Terraform

terraform init

Configuring Variables

export TF_VAR_project=$(gcloud config get-value project)
export TF_VAR_region="us-central1"
export TF_VAR_cluster_name="my-terraform-gke-cluster"

Provisioning a Cluster

terraform apply

Test the Cluster

watch gcloud container clusters list \
--filter name=my-terraform-gke-cluster
gcloud container clusters get-credentials my-terraform-gke-cluster \
--region us-central1
kubectl config get-contexts
kubectl get all --all-namespaces

Cleaning Up

terraform destroy

Deploying an Application

Deploy the Deployment

kubectl apply --filename hello-k8s-deploy.yaml
kubectl get deployment

Deploy the Service

kubectl apply --filename hello-k8s-svc.yaml
kubectl get service

Testing the Deployment

kubectl port-forward service/hello-kubernetes 8080:8080


Blog Source Code

Google Terraform Modules

GruntWork’s GKE Module

JetStack’s GKE Module

Learn Terraform: Provision a GKE Cluster


Linux NinjaPants Automation Engineering Mutant — exploring DevOps, Kubernetes, CNI, IAC

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store