Production-Ready Google Kubernetes Engine Module
This Terraform module provisions production-grade Google Kubernetes Engine (GKE) clusters on GCP, supporting both Autopilot and Standard cluster modes. It implements enterprise security controls including Workload Identity, Binary Authorization, Confidential Nodes, Dataplane V2 (Cilium), shielded nodes, and private cluster configurations. The module manages the full lifecycle: dedicated node service accounts with least-privilege IAM roles, configurable node pools with GPU support, cluster autoscaling (NAP), vertical pod autoscaling, maintenance windows, and integrated Cloud Logging/Monitoring.
GKE Cluster, Node Pools, Service Account, IAM Bindings
Log Writer, Metric Writer, Monitoring Viewer, AR Reader, GCR Reader
Comprehensive configuration for networking, security, autoscaling
Cluster, node pool, networking, service account details
google_container_cluster)Core cluster resource using google-beta provider. Supports Autopilot mode, release channels, private cluster config, master authorized networks, Dataplane V2, Binary Authorization, Confidential Nodes, VPA, and cluster-level autoscaling (NAP) with CPU/memory/GPU limits. Deletion protection is enabled by default.
google_container_node_pool)Dynamically created for Standard clusters via for_each. Each pool supports configurable machine types, disk size/type, preemptible/spot instances, GPU accelerators, taints, labels, auto-repair, auto-upgrade, and shielded instance config with secure boot and integrity monitoring.
google_service_account)Dedicated service account for GKE nodes with 5 least-privilege IAM roles: logging.logWriter, monitoring.metricWriter, monitoring.viewer, artifactregistry.reader, and storage.objectViewer. Optional Workload Identity User binding.
References existing VPC network and subnetwork via data sources. Configures pod and service secondary IP ranges, private cluster with optional private endpoint, and master authorized networks for API server access control.
| Control | Implementation | Default |
|---|---|---|
| Private Cluster | Nodes have no public IPs; optional private endpoint for master | Enabled |
| Workload Identity | Pod-to-GCP-service authentication without key files | Enabled |
| Dataplane V2 (Cilium) | eBPF-based networking with built-in network policy | Enabled |
| Network Policy | Calico-based (for non-Dataplane V2 clusters) | Enabled |
| Binary Authorization | Container image verification before deployment | Disabled |
| Confidential Nodes | Hardware-level memory encryption (AMD SEV) | Disabled |
| Shielded Nodes | Secure boot + integrity monitoring on all node pools | Always On |
| Master Auth Networks | CIDR-based access control to API server | Configurable |
| Least-Privilege SA | Dedicated node SA with 5 minimal IAM roles | Always On |
| Legacy Endpoints Disabled | Metadata server hardening via node metadata | Always On |
Enable Confidential Nodes + Binary Authorization + private endpoint for regulatory compliance. Use Stable release channel.
Private cluster with master authorized networks. Enable VPC Flow Logs on subnets. Use CMEK for etcd encryption.
Autopilot mode for cost optimization. Enable cluster autoscaling (NAP) with spot instances for batch workloads.
Standard cluster with GPU node pools (gpu_type, gpu_count). Use Rapid release channel for latest K8s features.
| Variable | Type | Default | Description |
|---|---|---|---|
project_id | string | required | GCP project ID |
cluster_name | string | required | Name of the GKE cluster |
region | string | required | GCP region |
network | string | required | VPC network name |
subnetwork | string | required | Subnetwork name |
enable_autopilot | bool | false | Enable Autopilot mode |
enable_private_cluster | bool | true | Enable private cluster |
enable_workload_identity | bool | true | Enable Workload Identity |
enable_dataplane_v2 | bool | true | Dataplane V2 (Cilium) |
release_channel | string | REGULAR | Release channel |
node_pools | list(object) | [default-pool] | Node pool configurations |
| Output | Description | Sensitive |
|---|---|---|
cluster_id | Unique identifier of the cluster | No |
cluster_endpoint | IP address of the cluster master | Yes |
cluster_ca_certificate | Base64-encoded CA certificate | Yes |
node_service_account_email | Node service account email | No |
workload_identity_pool | Workload Identity pool identifier | No |
# Initialize and deploy terraform init terraform plan -out=tfplan terraform apply tfplan # Get cluster credentials gcloud container clusters get-credentials $(terraform output -raw cluster_name) \ --region $(terraform output -raw cluster_location) \ --project YOUR_PROJECT_ID