Google Cloud GKE Module#
This Terraform module creates and manages Google Kubernetes Engine (GKE) clusters with comprehensive configuration options for production-ready Kubernetes deployments. It supports both standard and autopilot GKE clusters, and supports binary authorization configuration.
Overview#
The module provisions Google Kubernetes Engine clusters with enterprise-grade features including:
- Standard and Autopilot GKE Clusters: Support for both production-ready standard Kubernetes clusters and fully managed autopilot clusters.
- Multi-Node Pool Support: Flexible node pool configurations for standard clusters.
- Binary Authorization: Container image security policies to ensure only trusted images are deployed.
- Private Clusters: Secure network isolation for your clusters.
- Auto-scaling: Horizontal and vertical pod autoscaling.
- Backup & Recovery: GKE backup configurations for disaster recovery.
- Monitoring & Logging: Comprehensive observability with Google Cloud's operations suite.
Features#
- ✅ Standard GKE Clusters: Production-ready Kubernetes clusters.
- ✅ Autopilot GKE Clusters: Fully managed GKE clusters with a hands-off operational model.
- ✅ Multi-Node Pools: Multiple node pools with different configurations for standard clusters.
- ✅ Binary Authorization: Container image security and attestation.
- ✅ Private Clusters: Secure private networking.
- ✅ Cluster Autoscaling: Automatic node provisioning and scaling.
- ✅ Backup for GKE: Automated backup and recovery.
- ✅ Workload Identity: Secure service-to-service authentication.
- ✅ Add-ons Support: Configurable GKE add-ons (Istio, Config Connector, etc.).
- ✅ Release Channels: Automated cluster upgrades.
- ✅ Monitoring & Logging: Cloud Monitoring and Logging integration.
- ✅ Network Policies: Pod-level network security.
- ✅ Maintenance Windows: Controlled cluster maintenance.
Usage#
Autopilot GKE Cluster#
To create an Autopilot cluster, set the autopilot variable to true. In this mode, node pools are managed by Google, so the gke_nodepools variable is not used.
module "gke_cluster" {
source = "./modules/terraform-google-gke"
project_id = "my-project-id"
name = "my-autopilot-cluster"
location = "me-west1"
autopilot = true
vpc_config = {
network = "projects/my-project-id/global/networks/shared-vpc-network"
subnetwork = "projects/my-project-id/regions/me-west1/subnetworks/subnet-shared-prod-me-west1"
}
access_config = {}
release_channel = "REGULAR"
enable_addons = {
horizontal_pod_autoscaling = true
http_load_balancing = true
network_policy = true
}
enable_features = {
workload_identity = true
gateway_api = true
}
logging_config = {
enable_system_logs = true
}
monitoring_config = {
enable_system_metrics = true
enable_managed_prometheus = true # Managed Service for Prometheus cannot be disabled in Autopilot clusters
}
maintenance_config = {
daily_window_start_time = "03:00"
}
deletion_protection = false
binary_authorization = {
enabled = false
}
}
Standard GKE Cluster with Node Pools#
For a standard cluster, set autopilot to false and define your node pools in the gke_nodepools map.
module "gke_cluster_standard" {
source = "./modules/terraform-google-gke"
project_id = "my-project-id"
name = "my-standard-cluster"
location = "us-central1"
autopilot = false
vpc_config = {
network = "projects/my-project-id/global/networks/my-vpc"
subnetwork = "projects/my-project-id/regions/us-central1/subnetworks/my-subnet"
}
default_nodepool = {
remove_pool = true
}
gke_nodepools = {
"default-pool" = {
cluster_name = "my-standard-cluster"
location = "us-central1"
project_id = "my-project-id"
node_count = {
initial = 1
}
node_config = {
machine_type = "e2-medium"
}
}
}
}
Service Account#
The service account used by the GKE nodes requires the following IAM roles on the project:
roles/monitoring.viewerroles/monitoring.metricWriterroles/logging.logWriterroles/stackdriver.resourceMetadata.writerroles/container.defaultNodeServiceAccount
APIs#
The following APIs must be enabled on the project:
container.googleapis.commonitoring.googleapis.comlogging.googleapis.com
License#
This module is covered by a commercial license. Please see LICENSE for details.
Support#
This module is developed and maintained by MyOps Limited. For any support inquiries, please contact us at info@myops.co.il.
Requirements#
| Name | Version |
|---|---|
| terraform | ~> 1 |
| >= 6.28.0, < 7.0.0 | |
| google-beta | >= 6.28.0, < 7.0.0 |
Providers#
| Name | Version |
|---|---|
| >= 6.28.0, < 7.0.0 |
Modules#
| Name | Source | Version |
|---|---|---|
| nodepool | github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/gke-nodepool | v42.1.0 |
| terraform-google-gke-autopilot | github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/gke-cluster-autopilot | v42.1.0 |
| terraform-google-gke-standard | github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/gke-cluster-standard | v42.1.0 |
Resources#
| Name | Type |
|---|---|
| google_binary_authorization_policy.deployment_policy | resource |
Inputs#
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| access_config | Control plane endpoint and nodes access configurations. | object({ |
{} |
no |
| autopilot | Enable autopilot mode. | bool |
false |
no |
| backup_configs | Configuration for Backup for GKE. | object({ |
{} |
no |
| binary_authorization | Configurations for binary authorizations | object({ |
{} |
no |
| cluster_autoscaling | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({ |
null |
no |
| default_nodepool | Enable default nodepool. | object({ |
{} |
no |
| deletion_protection | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | bool |
true |
no |
| description | Cluster description. | string |
null |
no |
| enable_addons | Addons enabled in the cluster (true means enabled). | object({ |
{ |
no |
| enable_features | Enable cluster-level features. Certain features allow configuration. | object({ |
{ |
no |
| gke_nodepools | ## https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/blob/master/modules/gke-nodepool/variables.tf | map(object({ |
{} |
no |
| issue_client_certificate | Enable issuing client certificate. | bool |
false |
no |
| labels | Cluster resource labels. | map(string) |
{} |
no |
| location | Cluster zone or region. | string |
n/a | yes |
| logging_config | Logging configuration. | object({ |
{} |
no |
| maintenance_config | Maintenance window configuration. | object({ |
{ |
no |
| max_pods_per_node | Maximum number of pods per node in this cluster. | number |
110 |
no |
| min_master_version | Minimum version of the master, defaults to the version of the most recent official release. | string |
null |
no |
| monitoring_config | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({ |
{} |
no |
| name | Cluster name. | string |
n/a | yes |
| node_config | Node-level configuration. | object({ |
{} |
no |
| node_locations | Zones in which the cluster's nodes are located. | list(string) |
[] |
no |
| project_id | Cluster project id. | string |
n/a | yes |
| release_channel | Release channel for GKE upgrades. Clusters created in the Autopilot mode must use a release channel. Choose between "RAPID", "REGULAR", and "STABLE". | string |
"REGULAR" |
no |
| vpc_config | VPC-level configuration. | object({ |
n/a | yes |
Outputs#
| Name | Description |
|---|---|
| ca_certificate | Public certificate of the cluster (base64-encoded). |
| cluster | Cluster resource. |
| endpoint | Cluster endpoint. |
| id | Fully qualified cluster id. |
| location | Cluster location. |
| master_version | Master version. |
| name | Cluster name. |
| nodepool_ids | Fully qualified nodepool id. |
| nodepool_names | Nodepool name. |
| nodepool_service_account_email | Service account email. |
| notifications | GKE PubSub notifications topic. |
| self_link | Cluster self link. |
| workload_identity_pool | Workload identity pool. |