A terraform template to create a basic GKE cluster on Google Cloud Platform
This terraform template is designed to facilitate the creation of a 'vanilla' GCP GKE cluster for usage with testing/demos/etc. It will create:
- A new GKE cluster within an existing GCP Project
The output from running the template will contain the gcloud command to set the local Kubernetes config that you'll need in order to use the kubectl command line utility. That command will look something like this:
gcloud container clusters get-credentials k8s-demo --region us-east1 --project gke-basic-cluster
- git
- terraform
- google-cloud-sdk
- kubectl
- helm
The Google Cloud SDK can be installed via homebrew like so:
brew cask install google-cloud-sdk
Initialize the SDK (if you haven't already)
gcloud init
Follow the prompts to login, choose a cloud project and set the default compute region/zone (ie: us-east1-b)
- A Google Cloud Platform account
- A pre-created Project into which we will launch the GKE cluster
- A Service Account Key for the above Project (in JSON format)
- Kubernetes API (Enabled)
- Clone this repository
git clone https://github.com/howie-howerton/gcp-gke-basic-cluster.git
-
Edit the variables in the sample 'terraform.tfvars.changeme' file to suit your GCP environment
-
Remove the '.changeme' extension from terraform.tfvars.changeme so that the filename reads as: terraform.tfvars
-
Initialize terraform
terraform init
- Run 'terraform apply' to execute the template
terraform apply
This process typically takes 10-15 minutes. 6. Use the output for the 'kubeconfig_gcloud_cmd' variable to set the KUBECONFIG environment variable. It will look similar to this:
gcloud container clusters get-credentials k8s-demo --region us-east1 --project gke-basic-cluster
- You should now be able to manage your cluster with the kubectl cli utility:
kubectl cluster-info
kubectl get nodes
After you've finished with your cluster, you can destroy/delete it (to keep your Azure bill as low as possible)
terraform destroy -auto-approve
This process typically takes 10-15 minutes.