The Google Cloud Terraform provider now supports deployment of GKE Autopilot clusters. Learn how to use the new feature with a short example.
We are pleased to announce support for Google Kubernetes Engine (GKE) Autopilot in HashiCorp Terraform. Released in February 2021, GKE Autopilot is a new mode of operation for GKE that automates node configuration and management. GKE Autopilot gives you a hands-off approach to using Kubernetes on Google Cloud by eliminating node management operations and maximizing your cluster efficiency. This post will detail what GKE Autopilot does, and how to use it with Terraform.
Users can create a GKE cluster in standard mode or autopilot mode. The GKE standard mode is beneficial if you have a fair amount of experience managing the data plane of a Kubernetes environment and you would like to maintain control of resource consumption. On the other hand, GKE Autopilot provides management of nodes, pre-configuration of clusters, auto-scaling, auto-upgrades and security by Google Cloud so you can focus just on the development and not on the underlying infrastructure.
GKE Autopilot provides:
Autopilot helps shift several site reliability engineering (SRE) responsibilities from your team to Google Cloud’s, specifically for nodes and control planes where they help with cluster provisioning and maintenance. A comparison of both standard and autopilot modes can be found in Google Cloud’s GKE documentation.
GKE Autopilot can be enabled for your Kubernetes cluster by adding the variable enable_autopilot = true
to your GKE Terraform configuration.
In order to use the GKE Autopilot, you will need:
Here is an example workflow for enabling GKE Autopilot on a Kubernetes cluster using Terraform:
First, create a Terraform file that contains the GKE cluster.
Gke.tf
:
Write out a Terraform configuration to provision a GKE Autopilot cluster using google_container_cluser
and enable Autopilot for that cluster. Please note that while using Autopilot, you do not have to specify the number of nodes required; they will be automatically calculated for you.
Make sure to choose the correct version of the Google Cloud Terraform provider for your cluster: It must be 3.63.0, or later. If needed, you can update the provider using terraform init -upgrade
.
Versions.tf
:
Set the Terraform version to at least 0.14 and the provider version to 3.63.0 or higher.
Replace the values in your terraform.tfvars
file with your project_id
and region
. Terraform will use these values to target your project when provisioning your resources. Your terraform.tfvars
file should look like this:
After you have saved your customized variables file, initialize your Terraform workspace, which will download the provider and initialize it with the values mentioned in terraform.tfvars
file.
To provision your GKE Autopilot cluster, in your initialized directory, run terraform apply
and review the planned actions. Your terminal output should indicate the plan is running and what resources will be created.
You can see this terraform apply
will provision a VPC, subnet, and GKE Autopilot cluster. Confirm the apply
with a yes
. This process should take approximately 10 minutes. Upon successful application, your terminal prints the outputs defined in vpc.tf
and gke.tf
.
Once the cluster is deployed, you can review that it is live in your Google Cloud account:
The information page shows settings that can and can’t be changed. In the automation page, you can adjust the maintenance window after cluster creation.
GKE Autopilot is now active and providing automated node management, improved utilization, security, and reduced cost of maintenance. Users can leverage Google Cloud’s SRE tooling to maintain their nodes and pods.
Google Cloud offers a 99.95% SLA for the control plane of its GKE Autopilot clusters, and a 99.9% SLA for GKE Autopilot pods, while reducing the overall operational load required for managing the clusters.
For more information on how to get started with GKE using HashiCorp Terraform, please visit our tutorial on how to Provision a GKE Cluster Using Terraform or visit our developer documentation for detailed information on Using GKE with Terraform.
We would love to hear your feedback on this feature. You can post bugs and feature requests for this provider by opening an issue on the GitHub Repository.
Improve the developer experience writing Terraform code with the help of generative AI powered by Amazon CodeWhisperer.
HashiCorp’s Terraform provider for AWS now enables users to manage their S3 Express buckets.
A new view in the HashiCorp Terraform extension for Visual Studio Code shows your Terraform Cloud workspaces and runs, reducing context-switching.