The gke-cluster module lets you create a Google Kubernetes Engine (GKE) cluster.
By using this module, you automate the provisioning of managed Kubernetes
environments. This automation provides a scalable and secure foundation for your
containerized workloads.
For the complete list of inputs and outputs for this module, see the
gke-cluster module
page in the Google Kubernetes Engine GitHub repository.
Before you begin
Before you begin, verify that you meet the following requirements:
- You have installed and configured GKE. For installation instructions, see Set up GKE.
- You have an existing cluster blueprint. You can use and modify an existing
blueprint or create one from scratch. For a working example of a blueprint
configured for GKE, see the
examples/hpc-gke.yamlfile. For more information about creating and customizing blueprints, see Cluster blueprint. - To view a complete list of blueprints that support GKE, go to the Cluster blueprint catalog page, click the Select scheduler menu, and then select GKE.
- The
gke-clustermodule doesn't create a full active cluster or execute the workload. It provisions a managed GKE cluster to host your containerized workloads.
Required roles
To get the permissions that you need to create the GKE cluster and node pools, ask your administrator to grant you the following IAM roles on your project:
- Kubernetes Engine Admin (
roles/container.admin) - Service Account User (
roles/iam.serviceAccountUser)
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Create a GKE cluster
The following example creates a GKE cluster and a
Virtual Private Cloud (VPC) network that supports GKE. To view
the complete configuration, see the
examples/hpc-gke.yaml
example on GitHub.
- id: network1
source: modules/network/vpc
settings:
subnetwork_name: gke-subnet
secondary_ranges:
gke-subnet:
- range_name: pods
ip_cidr_range: 10.4.0.0/14
- range_name: services
ip_cidr_range: 10.0.32.0/20
- id: gke_cluster
source: modules/scheduler/gke-cluster
use: [network1]
Create a VPC network
This module creates a VPC-native
cluster. A VPC-native cluster uses
alias IP addresses, which require the subnetwork to have secondary IP address
ranges for pods and services. In the preceding example, the vpc module creates
these secondary ranges. By default, the gke-cluster module searches for ranges
that have the pods and services names. You can configure these names by
using the pods_ip_range_name setting and the services_ip_range_name setting.
Use a pre-existing VPC network
To deploy a GKE cluster into an existing VPC
network and subnetwork by using the pre-existing-vpc
module, verify that the target
subnetwork has Private Google Access
enabled and includes secondary IP address ranges for pods and services:
- id: existing_network
source: modules/network/pre-existing-vpc
settings:
network_name: my-existing-vpc
subnetwork_name: my-existing-subnet
- id: gke_cluster
source: modules/scheduler/gke-cluster
use: [existing_network]
settings:
enable_private_endpoint: false
pods_ip_range_name: pods
services_ip_range_name: services
release_channel: REGULAR
The master_ipv4_cidr_block setting controls how GKE allocates
the IP address for the control plane endpoint:
- By default, the
master_ipv4_cidr_blocksetting has a value ofnull. When this setting isnull, GKE uses Private Service Connect and reserves the private endpoint IP address for the control plane directly from the primary subnetwork of the cluster (subnetwork_self_link). This behavior prevents/28CIDR collisions when you deploy into pre-existing VPC networks or run multiple GKE clusters in the same VPC network. - If you need GKE to provision a dedicated
/28subnetwork for the control plane endpoint instead, then set themaster_ipv4_cidr_blocksetting to an unused/28IPv4 CIDR range in your VPC network, such as10.0.0.32/28. - The
master_ipv4_cidr_blocksetting applies only when theenable_private_nodessetting istrue(the default). - The
master_ipv4_cidr_blocksetting is immutable after you create the cluster. If you change its value on an existing cluster, then Terraform replaces the cluster.
Configure multi-networking
To enable
multi-networking,
supply the multivpc module to the gke-cluster module. When you supply a
multivpc module, the cluster enables multi-networking and
GKE Dataplane V2.
The following example demonstrates how to configure this relationship:
- id: network
source: modules/network/vpc
settings:
subnetwork_name: gke-subnet
secondary_ranges:
gke-subnet:
- range_name: pods
ip_cidr_range: 10.4.0.0/14
- range_name: services
ip_cidr_range: 10.0.32.0/20
- id: multinetwork
source: modules/network/multivpc
settings:
network_name_prefix: multivpc-net
network_count: 8
global_ip_address_range: 172.16.0.0/12
subnetwork_cidr_suffix: 16
- id: gke-cluster
source: modules/scheduler/gke-cluster
use: [network, multinetwork]
settings:
cluster_name: $(vars.deployment_name)
To view a complete multi-networking implementation, see the
examples/gke-a3-megagpu/gke-a3-megagpu.yaml
example on GitHub.
Enable the GKE Inference Gateway
If you set the enable_inference_gateway setting to true, then the module
enables the HttpLoadBalancing add-on and deploys the Inference Gateway custom
resource definitions (CRDs). To use this feature, your VPC
network must contain a subnetwork that has the purpose attribute set to a
value of REGIONAL_MANAGED_PROXY.
For more information, see About GKE Inference Gateway.
Enable CSI drivers for storage
The gke-cluster module lets you enable Container Storage Interface (CSI)
drivers by using the following settings:
enable_filestore_csi: supports Filestore storage.enable_gcsfuse_csi: supports Cloud Storage FUSE storage.enable_managed_lustre_csi: supports Google Cloud Managed Lustre storage.enable_multi_tier_checkpointing: supports Multi-Tier Checkpointing for machine learning workloads.enable_persistent_disk_csi: supports Persistent Disk and Google Cloud Hyperdisk storage. This setting istrueby default.
Except for the enable_persistent_disk_csi setting, all CSI driver settings
default to false. If you plan to use a storage module in your deployment, then
you must set the corresponding CSI driver setting to true.
Define the GKE version
By default, the gke-cluster module provisions clusters using the 1.35.
version prefix. If your workload requires a different GKE
version, you must override this default behavior by specifying a new prefix in
the version_prefix setting.
Limitations
The gke-cluster module has the following limitations:
- Autopilot mode isn't supported. This module creates only
Standard clusters. You can configure node auto-provisioning by using
the
cluster_autoscalingsetting, and you can choose zonal or regional availability by using thecluster_availability_typesetting. - General add-on configuration is limited to the add-ons that the module exposes
as inputs. For the full list of inputs, see the
gke-clustermodule page in the GKE GitHub repository.
What's next
- For the complete list of inputs and outputs for this module, see the
gke-clustermodule page in the GKE GitHub repository.