The `pre-existing-gke-cluster` module lets you discover a
Google Kubernetes Engine (GKE) cluster that already exists in
Google Cloud. By using this module, you can extract cluster
attributes to uniquely identify the cluster for use by other modules. The module
outputs align with the
[`gke-cluster`](https://docs.cloud.google.com/cluster-toolkit/docs/modules/gke-cluster) module, which lets
you use the `pre-existing-gke-cluster` module as a direct substitute.

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

## Before you begin

Before you begin, verify that you meet the following requirements:

- You have installed and configured Cluster Toolkit. For installation instructions, see [Set up
  Cluster Toolkit](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. To view a working example of a blueprint configured for the `pre-existing-gke-cluster` module, 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** . For more information about creating and customizing blueprints, see [Cluster blueprint](https://docs.cloud.google.com/cluster-toolkit/docs/setup/cluster-blueprint).

### Required roles


To get the permissions that
you need to discover the existing GKE cluster,

ask your administrator to grant you the
[Kubernetes Engine Cluster Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/container#container.clusterViewer) (`roles/container.clusterViewer`) IAM role on your project.


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).


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).

## Use an existing GKE cluster

The following example demonstrates how to discover an existing GKE cluster
named `my-gke-cluster` in the `us-central1` region.

    - id: existing-gke-cluster
      source: modules/scheduler/pre-existing-gke-cluster
      settings:
        project_id: $(vars.project_id)
        cluster_name: my-gke-cluster
        region: us-central1

    - id: compute_pool
      source: modules/compute/gke-node-pool
      use: [existing-gke-cluster]

By using the `use` keyword, the `gke-node-pool` module accepts the
`cluster_id` input variable. This variable identifies the existing
GKE cluster that hosts the new GKE node pool.

> [!NOTE]
> **Note:** The module infers the `project_id` setting and the `region` setting from the deployment variables of the same name. We include them in the preceding example for clarity.

### Configure multi-networking

To create network objects in your GKE cluster, you can supply a
[`multivpc` module](https://docs.cloud.google.com/cluster-toolkit/docs/modules/multivpc) to the
`pre-existing-gke-cluster` module instead of applying a manifest manually.

      - id: network
        source: modules/network/vpc

      - 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: existing-gke-cluster
        source: modules/scheduler/pre-existing-gke-cluster
        use: [multinetwork]
        settings:
          # Multi-networking must be enabled in advance during cluster creation.
          cluster_name: $(vars.deployment_name)

## What's next

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