This document shows how to associate one or more Google Cloud projects with a
cluster in Google Distributed Cloud.

The instructions here are complete. For a shorter introduction to using a
Google Cloud project, see
[Set up minimal infrastructure](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/minimal-infrastructure.md.txt).

## Before you begin

[Install Google Cloud CLI](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/cloud-sdk.md.txt).

## Fleet host project

Every admin cluster must be registered to a
[fleet](https://docs.cloud.google.com/anthos/fleet-management/docs).
And every user cluster managed by an admin cluster must be registered to the
same fleet as the admin cluster.

When an admin or user cluster is registered to a fleet, it is associated with a
*fleet host project*. An admin cluster and all the user clusters it manages
have the same fleet host project. In the Google Cloud console, in the fleet host
project, you can see and manage your admin and user clusters.

Choose a Google Cloud project to serve as your fleet host project. You can choose
an existing project, or you can create a new one. Make a note of the project
ID. You need the ID of your fleet host project in the steps that follow.

### Enable APIs in your fleet host project

In your fleet host project, enable the required APIs:

### Linux and macOS

Enable the following APIs in your fleet host project:

```
gcloud services enable --project FLEET_HOST_PROJECT_ID \
    anthos.googleapis.com \
    container.googleapis.com \
    gkehub.googleapis.com \
    gkeconnect.googleapis.com \
    connectgateway.googleapis.com \
    monitoring.googleapis.com \
    kubernetesmetadata.googleapis.com \
    logging.googleapis.com \
    opsconfigmonitoring.googleapis.com \
    serviceusage.googleapis.com \
    iam.googleapis.com \
    cloudresourcemanager.googleapis.com
```

If you want to manage the lifecycle of clusters in the
Google Cloud console, the Google Cloud CLI, or
[Terraform](https://www.terraform.io/), enable these
additional APIs in your fleet host project:

```
gcloud services enable --project FLEET_HOST_PROJECT_ID \
    gkeonprem.googleapis.com \
    anthosaudit.googleapis.com \
    storage.googleapis.com
```

### Windows

Enable the following APIs in your fleet host project:

```
gcloud services enable --project FLEET_HOST_PROJECT_ID ^
    anthos.googleapis.com ^
    container.googleapis.com ^
    gkehub.googleapis.com ^
    gkeconnect.googleapis.com ^
    connectgateway.googleapis.com ^
    monitoring.googleapis.com ^
    kubernetesmetadata.googleapis.com ^
    logging.googleapis.com ^
    opsconfigmonitoring.googleapis.com ^
    serviceusage.googleapis.com ^
    iam.googleapis.com ^
    cloudresourcemanager.googleapis.com
```

If you want to manage the lifecycle of user clusters in the
Google Cloud console, the Google Cloud CLI, or
[Terraform](https://www.terraform.io/), enable these
additional APIs in your fleet host project:

```
gcloud services enable --project FLEET_HOST_PROJECT_ID ^
    gkeonprem.googleapis.com ^
    anthosaudit.googleapis.com ^
    storage.googleapis.com
```

### Grant roles to service accounts on your fleet host project

Your connect-register service account must be granted certain roles on your
fleet host project. For details see
[Connect-register service account](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/service-accounts.md.txt#connect_register_service_account).

Your logging-monitoring service account must be granted certain roles on your
fleet host project. For details, see
[Logging-monitoring service account](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/service-accounts.md.txt#logging_monitoring_service_account).

Your audit logging service account must be granted certain roles on your
fleet host project. For details, see
[Audit logging service account](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/service-accounts.md.txt#audit_logging_service_account).

### Register a cluster to a fleet

You register a cluster to a fleet when you create the cluster. The details
of registration depend on what tool you use to create the cluster:

| Tool | How to register |
|---|---|
| `gkectl` | Fill in the [gkeConnect.projectID](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/admin-cluster-configuration-file-latest.md.txt#gkeconnect-projectid-field) field in the cluster configuration file. |
| Google Cloud console | The cluster is automatically registered. The Google Cloud project that you use to create the cluster becomes the fleet host project. |
| Terraform | Fill in the `project_id` field in the [.tfvars file](https://registry.terraform.io/providers/terraform-redhat/rhcs/latest/docs/guides/terraform-vars). |
| gcloud CLI | When you call `gcloud container vmware clusters create`, provide a value for `--project`. |

## Parent project of your component access service account

Before you create a cluster, you must have a service account that
Google Distributed Cloud can use to download components from Artifact Registry.
This service account is called your *component access service account*.

The Google Cloud project where you created your component access service
account is called the *parent* of your component access service account. This
project can be the same as your fleet host project, or it can be different. For
more information about service accounts and parent projects see
[Understanding service accounts and Google Cloud projects](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/service-accounts.md.txt#service_accounts_and_projects).

To enable the required APIs for the parent project of your component access
service account:

### Linux and macOS

```
gcloud services enable --project [PARENT_PROJECT_ID] \
    serviceusage.googleapis.com \
    iam.googleapis.com \
    cloudresourcemanager.googleapis.com
```

### Windows

```
gcloud services enable --project [PARENT_PROJECT_ID] ^
    serviceusage.googleapis.com ^
    iam.googleapis.com ^
    cloudresourcemanager.googleapis.com
```

## What's next

[Create service accounts and keys](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/vmware/docs/how-to/service-accounts.md.txt).