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](https://github.com/GoogleCloudPlatform/cluster-toolkit/tree/main/modules/scheduler/gke-cluster#inputs)
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](https://docs.cloud.google.com/cluster-toolkit/docs/setup/configure-environment).
- 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.yaml`](https://github.com/GoogleCloudPlatform/cluster-toolkit/blob/main/examples/hpc-gke.yaml) file. For more information about creating and customizing blueprints, see [Cluster blueprint](https://docs.cloud.google.com/cluster-toolkit/docs/setup/cluster-blueprint.md.txt).
- To view a complete list of blueprints that support GKE, go to the [Cluster blueprint
  catalog](https://docs.cloud.google.com/cluster-toolkit/docs/setup/cluster-blueprint-catalog) page, click the **Select scheduler** menu, and then select **GKE**.
- The `gke-cluster` module 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](https://docs.cloud.google.com/iam/docs/roles-permissions/container.md.txt#container.admin) (`roles/container.admin`)
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## 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`](https://github.com/GoogleCloudPlatform/cluster-toolkit/blob/main/examples/hpc-gke.yaml)
example on GitHub.

```yaml
  - 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](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/alias-ips). 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](https://docs.cloud.google.com/cluster-toolkit/docs/modules/pre-existing-vpc), verify that the target
subnetwork has [Private Google Access](https://docs.cloud.google.com/vpc/docs/private-google-access.md.txt)
enabled and includes secondary IP address ranges for pods and services:

```yaml
  - 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
```

> [!NOTE]
> **Note:** The `enable_private_endpoint` setting defaults to `true`. If you run the [`gcluster deploy` command](https://docs.cloud.google.com/cluster-toolkit/docs/reference/gcluster-deploy.md.txt) from outside the VPC network with modules that manage Kubernetes or Helm resources, then set the `enable_private_endpoint` setting to `false`. When you use this configuration, add your IP address range to the allowlist by using the `master_authorized_networks` setting. Alternatively, to run `kubectl` and [`gcluster job`](https://docs.cloud.google.com/cluster-toolkit/docs/reference/gcluster-job.md.txt) commands from outside the network, set the `enable_external_dns_endpoint` setting to `true`.

The `master_ipv4_cidr_block` setting controls how GKE allocates
the IP address for the control plane endpoint:

- By default, the `master_ipv4_cidr_block` setting has a value of `null`. When this setting is `null`, 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 `/28` CIDR 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 `/28` subnetwork for the control plane endpoint instead, then set the `master_ipv4_cidr_block` setting to an unused `/28` IPv4 CIDR range in your VPC network, such as `10.0.0.32/28`.
- The `master_ipv4_cidr_block` setting applies only when the `enable_private_nodes` setting is `true` (the default).
- The `master_ipv4_cidr_block` setting 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](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/about-multinetwork-support-for-pods.md.txt),
supply the `multivpc` module to the `gke-cluster` module. When you supply a
`multivpc` module, the cluster enables multi-networking and
[GKE Dataplane V2](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/dataplane-v2.md.txt).

The following example demonstrates how to configure this relationship:

```yaml
  - 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`](https://github.com/GoogleCloudPlatform/cluster-toolkit/blob/main/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](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/serve-with-gke-inference-gateway.md.txt).

## 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](https://docs.cloud.google.com/filestore/docs.md.txt) storage.
- `enable_gcsfuse_csi`: supports [Cloud Storage FUSE](https://docs.cloud.google.com/storage/docs/gcs-fuse) storage.
- `enable_managed_lustre_csi`: supports [Google Cloud Managed Lustre](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/managed-lustre.md.txt) storage.
- `enable_multi_tier_checkpointing`: supports [Multi-Tier Checkpointing](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/machine-learning/training/multi-tier-checkpointing.md.txt) for machine learning workloads.
- `enable_persistent_disk_csi`: supports [Persistent Disk](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/gce-pd-csi-driver.md.txt) and [Google Cloud Hyperdisk](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/hyperdisk.md.txt) storage. This setting is `true` by 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_autoscaling` setting, and you can choose zonal or regional availability by using the `cluster_availability_type` setting.
- 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-cluster` module](https://github.com/GoogleCloudPlatform/cluster-toolkit/tree/main/modules/scheduler/gke-cluster#inputs) page in the GKE GitHub repository.

## What's next

- For the complete list of inputs and outputs for this module, see the [`gke-cluster` module](https://github.com/GoogleCloudPlatform/cluster-toolkit/tree/main/modules/scheduler/gke-cluster#inputs) page in the GKE GitHub repository.