# Prepare to setup the Gateway API for Cloud Service Mesh

This page describes how to install the required custom resource definitions
for the gateway into your cluster.

## Limitations

- Having a mix of `gateway` config-api and `istio` config-api clusters in the same fleet is not supported. Make sure the config-api is set to `gateway` for all the clusters in your fleet. Use the `gcloud container fleet mesh describe --project FLEET_PROJECT_ID` command to see what you have configured for your fleet.
- Multi-cluster service discovery and load balancing is not supported for `gateway` config-api clusters.
- If a cluster is onboarded using the existing `--management automatic` flag then the cluster starts using the `istio` configuration API and cannot change to `gateway` API.
- Only FQDNs are supported. Short names are not supported.

## Data plane management considerations

For new pods, Google manages which proxy version is injected. Note that the
managed data plane relies on the Google Kubernetes Engine (GKE) release channel to
determine the proxy version.

For existing pods, proxy management is done passively, driven by the natural
lifecycle of the pods in the cluster. To trigger the
update and re-inject new versions of the proxy, restart your workloads.

## Prerequisites

As a starting point, this guide assumes that you have already
[created a Google Cloud project](https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt#before-you-begin) and
[installed `kubectl`](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl.md.txt#install_kubectl).

## Before you begin

<br />

## Create and register a GKE cluster

### gcloud


Create a GKE cluster:

```bash
gcloud container clusters create CLUSTER_NAME \
--location=LOCATION \
--enable-ip-alias \
--scopes=https://www.googleapis.com/auth/cloud-platform \
--release-channel=regular \
--project=PROJECT_ID \
--gateway-api=standard \
--workload-pool=PROJECT_ID.svc.id.goog \
--workload-metadata=GKE_METADATA
```

where:

- <var translate="no">CLUSTER_NAME</var> is the name of your cluster
- <var translate="no">LOCATION</var> is the location of your cluster
- <var translate="no">PROJECT_ID</var> is the project ID of your cluster

### Console

1. Go to the **Google Kubernetes Engine** page in the Google Cloud console.

   [Go to Google Kubernetes Engine](https://console.cloud.google.com/kubernetes/list)
2. Click **Create**.

3. In the **Standard** section, click **Configure**.

4. In the **Cluster basics** section, complete the following:

   1. Enter the **Name** for your cluster.
   2. For the **Location type** , select a [Compute Engine region](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) for your cluster.
5. In the navigation pane, click **default-pool** under **Node Pools**
   section, and select **Security**.

6. In the **Access scopes** list, select **Set access for each API** , and
   set **Cloud Platform** as **Enabled**.

7. In the navigation pane, click **Networking**.

8. In the **Load Balancer, Ingress, and Gateway** section, select **Enable Gateway API**.

9. In the navigation pane, click **Advanced settings**.

10. In the **Workload identity** row, verify that **Details** shows **Enabled** . If it shows **Disabled** , click **Edit feature configuration** , select **Enable Workload Identity** , and then click **Save**.

11. Click **Create**.

After the cluster is created,

1. Register your cluster to a [fleet](https://docs.cloud.google.com/kubernetes-engine/fleet-management/docs.md.txt#introducing_fleets):

   ```bash
   gcloud container fleet memberships register CLUSTER_NAME \
   --gke-cluster LOCATION/CLUSTER_NAME \
   --project=PROJECT_ID
   ```
2. Verify that the cluster is registered to the fleet:

   ```bash
   gcloud container fleet memberships list --project=PROJECT_ID
   ```

   The output is similar to:

       NAME            EXTERNAL_ID                             LOCATION
       my-cluster      91980bb9-593c-4b36-9170-96445c9edd39    us-west1

## Set up permissions

Note that the following commands grant permission to all authenticated users,
but you can use Workload Identity Federation for GKE to grant permission to only select accounts.
For details on how Workload Identity Federation for GKE works,
see [About Workload Identity Federation for GKE](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/workload-identity.md.txt).
To configure Workload Identity Federation for GKE, see
[Authenticate to Google Cloud APIs from GKE workloads](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/workload-identity.md.txt).

Grant the `trafficdirector.client` role:

    gcloud projects add-iam-policy-binding PROJECT_ID \
        --member "group:PROJECT_ID.svc.id.goog:/allAuthenticatedUsers/" \
        --role "roles/trafficdirector.client"

## Enable Cloud Service Mesh

1. Enable the mesh feature:

   ```bash
   gcloud container fleet mesh enable --project PROJECT_ID
   ```
2. Update the mesh to use the Gateway API:

   ```bash
   gcloud alpha container fleet mesh update \
   --config-api gateway \
   --memberships CLUSTER_NAME \
   --project PROJECT_ID
   ```
3. Verify the update by describing the status of Cloud Service Mesh resource:

   ```bash
   gcloud alpha container fleet mesh describe \
   --project PROJECT_ID
   ```

## Set your fleet new memberships to use the Gateway API by default (optional)

Alternatively, you can create [fleet-level default settings](https://docs.cloud.google.com/service-mesh/docs/onboarding/provision-control-plane.md.txt#configure_your_fleet) for new GKE clusters registered to the fleet during cluster creation to be automatically configured with Gateway API.

1. Create a YAML file specifying using Gateway API:

   ```bash
   echo "configapi: gateway" > mesh.yaml
   ```

   > [!NOTE]
   > **Note:** `management` and `config-api` shouldn't be configured at the same time.

2. Update your mesh:

   ```bash
   gcloud alpha container fleet mesh update --project FLEET_PROJECT_ID \
       --fleet-default-member-config mesh.yaml
   ```
3. Create a cluster and register them to your fleet in one step to use the default configuration:

   ```bash
   gcloud container clusters create CLUSTER_NAME \
       --project PROJECT_ID \
       --fleet-project FLEET_PROJECT_ID \
       --location=LOCATION \
   ```
4. Enable Workload Identity Federation for GKE and run the GKE Metadata Server on your node.

## Install custom resource definitions

Generate a kubeconfig entry for your cluster:

```
gcloud container clusters get-credentials CLUSTER_NAME --location LOCATION --project PROJECT_ID
```

<br />

where:

- <var translate="no">CLUSTER_NAME</var> is the name of your cluster
- <var translate="no">LOCATION</var> is the location of your cluster
- <var translate="no">PROJECT_ID</var> is the project ID of your cluster

Install the GRPCRoute custom resource definition (CRD):

```bash
curl https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/v1.1.0/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml \
| kubectl apply -f -
```

The output is similar to:

    customresourcedefinition.apiextensions.k8s.io/grpcroutes.gateway.networking.k8s.io created

## What's next

- [Set up an Envoy sidecar service mesh on GKE](https://docs.cloud.google.com/service-mesh/docs/gateway/set-up-envoy-mesh.md.txt)
- [Set up a proxyless gRPC service mesh on GKE](https://docs.cloud.google.com/service-mesh/docs/gateway/proxyless-grpc-mesh.md.txt)