# Prepare to setup the Gateway API for Cloud Service Mesh

> [!WARNING]
>
> **Preview**
>
>
> This product or feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section
> of the [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA products and features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

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

## 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 />

4. Generate a kubeconfig entry for your cluster:

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

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

## Create and register a GKE cluster

1. 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
   ```

   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
2. Enable Workload Identity Federation for GKE:

   ```bash
   gcloud container clusters update CLUSTER_NAME \
   --location LOCATION \
   --workload-pool=PROJECT_ID.svc.id.goog
   ```
3. Run the GKE Metadata Server on your node:

   ```bash
   gcloud container node-pools update default-pool \
   --cluster=CLUSTER_NAME \
   --location=LOCATION \
   --workload-metadata=GKE_METADATA
   ```
4. Register your cluster to a [fleet](https://docs.cloud.google.com/kubernetes-engine/fleet-management/docs.md.txt#introducing_fleets):

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

   ```bash
   gcloud container hub 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.

1. Grant the `trafficdirector.client` role:

   ```bash
   gcloud projects add-iam-policy-binding PROJECT_ID \
       --member "group:PROJECT_ID.svc.id.goog:/allAuthenticatedUsers/" \
       --role "roles/trafficdirector.client"
   ```
2. Grant the `container.developer` role:

   ```bash
   gcloud projects add-iam-policy-binding PROJECT_ID \
   --member "serviceAccount:service-PROJECT_NUMBER@container-engine-robot.iam.gserviceaccount.com" \
   --role "roles/container.developer"
   ```

   where <var translate="no">PROJECT_NUMBER</var> is your project number.
3. Grant the `compute.networkAdmin` role:

   ```bash
   gcloud projects add-iam-policy-binding PROJECT_ID \
   --member "serviceAccount:service-PROJECT_NUMBER@container-engine-robot.iam.gserviceaccount.com" \
   --role "roles/compute.networkAdmin"
   ```

   where <var translate="no">PROJECT_NUMBER</var> is your project number.

## Enable Cloud Service Mesh

1. Enable the mesh feature:

   ```bash
   gcloud container hub 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
   ```

## Install custom resource definitions

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/v1.22/docs/gateway/set-up-envoy-mesh.md.txt)
- [Set up a proxyless gRPC service mesh on GKE](https://docs.cloud.google.com/service-mesh/v1.22/docs/gateway/proxyless-grpc-mesh.md.txt)