为 Gemini Enterprise Agent Platform Pipelines 配置 Google Cloud 项目

在使用 Agent Platform Pipelines 编排机器学习 (ML) 流水线之前,您必须设置 Google Cloud 项目。第一次运行流水线时,系统会在您的 Google Cloud 项目中创建一些资源,例如 Vertex ML Metadata 使用的元数据存储区。

请按照以下说明为 Agent Platform Pipelines 配置项目。

  1. 创建项目并将其配置为与 Agent Platform Pipelines搭配使用。 Google Cloud

  2. 如果您未指定服务帐号,Agent Platform Pipelines 将使用 Compute Engine 默认服务帐号来运行流水线。 如需详细了解 Compute Engine 默认服务帐号,请参阅 使用 Compute Engine 默认服务账号

    我们建议您创建服务帐号以运行流水线,然后 向此账号授予运行流水线所需的 Google Cloud 资源的 精细权限

  3. Agent Platform Pipelines 使用 Cloud Storage 来存储流水线运行的工件。创建 Cloud Storage 存储桶 并向您的服务帐号授予对此存储桶的访问权限

  4. Agent Platform Pipelines 使用 Vertex ML Metadata 存储流水线运行创建的元数据。当您首次运行流水线时,如果项目的元数据存储区不存在,Gemini Enterprise Agent Platform 会创建项目的元数据存储区。

    如果您希望使用客户管理的加密密钥 (CMEK) 来加密数据,则可以手动 创建使用 CMEK 密钥的元数据存储区,然后再运行流水线。否则,如果项目中没有现有的默认元数据存储区,Gemini Enterprise Agent Platform 会使用您首次运行流水线时使用的 CMEK 密钥创建项目的元数据存储区。创建元数据存储区后,它使用的 CMEK 密钥与流水线运行中使用的 CMEK 密钥不同。

设置 Google Cloud 项目

请按照以下说明创建 Google Cloud 项目并将其配置 为与 Agent Platform Pipelines 搭配使用。

  1. 登录您的 Google Cloud 账号。如果您是新手 Google Cloud, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Gemini Enterprise Agent Platform, Compute Engine, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  5. 安装 Google Cloud CLI。

  6. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  7. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  8. 初始化 gcloud CLI 后,对其进行更新并安装所需组件:

    gcloud components update
    gcloud components install beta
  9. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  10. Verify that billing is enabled for your Google Cloud project.

  11. Enable the Gemini Enterprise Agent Platform, Compute Engine, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  12. 安装 Google Cloud CLI。

  13. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  14. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  15. 初始化 gcloud CLI 后,对其进行更新并安装所需组件:

    gcloud components update
    gcloud components install beta

配置具有精细权限的服务帐号

运行流水线时,您可以指定服务账号。您的流水线运行以此服务账号的权限执行。

如果您未指定服务账号,则流水线运行将使用 Compute Engine 默认服务账号。如需详细了解 Compute Engine 默认服务账号,请参阅使用 Compute Engine 默认服务账号

  • 请按照以下说明创建服务账号,并向此账号授予对 Google Cloud 资源的精细权限。

    1. 运行以下命令以创建服务账号。

      gcloud iam service-accounts create SERVICE_ACCOUNT_ID \
          --description="DESCRIPTION" \
          --display-name="DISPLAY_NAME" \
          --project=PROJECT_ID
      

      替换以下值:

      • SERVICE_ACCOUNT_ID:服务账号的 ID。
      • DESCRIPTION:(可选)服务账号的说明。
      • DISPLAY_NAME:此服务账号的显示名。
      • PROJECT_ID:要在其中创建服务账号的项目。

      详细了解如何创建服务账号

    2. 向您的服务帐号授予对 Gemini Enterprise Agent Platform 的访问权限。 请注意,访问权限更改可能需要一段时间才能拓展。 如需了解详情,请参阅访问权限更改传播

      gcloud projects add-iam-policy-binding PROJECT_ID \
          --member="serviceAccount:SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com" \
          --role="roles/aiplatform.user"
      

      替换以下值:

      • PROJECT_ID:在其中创建您的服务账号的项目。
      • SERVICE_ACCOUNT_ID:服务帐号的 ID。
    3. 您可以使用 Artifact Registry 托管容器映像和 Kubeflow Pipelines 模板。

      如需详细了解 Artifact Registry,请参阅 Artifact Registry 文档

    4. 向您的服务账号授予对在流水线中使用的任何 Google Cloud 资源的访问权限。

      gcloud projects add-iam-policy-binding PROJECT_ID \
          --member="serviceAccount:SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com" \
          --role="ROLE_NAME"
      

      替换以下值:

      • PROJECT_ID:在其中创建您的服务账号的项目。
      • SERVICE_ACCOUNT_ID:服务账号的 ID。
      • ROLE_NAME:要授予此 服务帐号的 Identity and Access Management 角色。
    5. 如需使用 Agent Platform Pipelines 以此服务帐号身份运行流水线,请运行以下命令来为您的用户账号授予服务帐号的 roles/iam.serviceAccountUser 角色。

      gcloud iam service-accounts add-iam-policy-binding \
          SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com \
          --member="user:USER_EMAIL" \
          --role="roles/iam.serviceAccountUser"
      

      替换以下值:

      • SERVICE_ACCOUNT_ID:服务账号的 ID。
      • PROJECT_ID:在其中创建您的服务账号的项目。
      • USER_EMAIL:以此服务帐号身份运行 流水线的用户的电子邮件地址。
  • 如果您希望使用 Compute Engine 默认服务帐号来运行流水线,请启用 Compute Engine API 并向默认服务帐号授予对 Gemini Enterprise Agent Platform 的访问权限。 请注意,访问权限更改可能需要一段时间才能拓展。 如需了解详情,请参阅访问权限更改传播

    gcloud projects add-iam-policy-binding PROJECT_ID \
        --member="serviceAccount:PROJECT_NUMBER-compute@developer.gserviceaccount.com" \
        --role="roles/aiplatform.user"
    

    替换以下值:

    • PROJECT_ID:在其中创建您的默认服务账号的项目。
    • PROJECT_NUMBER:创建默认服务 账号的项目的编号。

    启用 API 所需的角色

    如需启用 API,您需要拥有 serviceusage.services.enable 权限。如果您 创建了项目,则可能已通过 所有者角色 (roles/owner) 拥有此权限。否则,您可以通过 Service Usage Admin 角色 (roles/serviceusage.serviceUsageAdmin) 获得此权限。 了解如何授予角色

    启用 API

为流水线工件配置 Cloud Storage 存储桶

Agent Platform Pipelines 使用 Cloud Storage 存储流水线运行的工件。按照以下说明创建 Cloud Storage 存储桶,并向您的服务帐号(或 Compute Engine 默认服务帐号)授予读取和写入该存储桶中的对象的权限。

  1. 运行以下命令,在要在其中运行流水线的区域中创建 Cloud Storage 存储桶。

    gcloud storage buckets create gs://BUCKET_NAME --location=BUCKET_LOCATION --project=PROJECT_ID
    

    替换以下值:

    • PROJECT_ID:指定与您的存储桶关联的项目。
    • BUCKET_LOCATION:指定存储桶的位置,例如 US-CENTRAL1
    • BUCKET_NAME:您要为存储桶指定的名称(须遵循命名要求)。例如 my-bucket

    详细了解如何创建 Cloud Storage 存储桶

  2. 运行以下命令,向您的服务账号授予读写您在上一步创建的存储桶中的流水线工件的访问权限。

    gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \
    --member=serviceAccount:SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com \
    --role=roles/storage.objectUser
    

    替换以下值:

    • SERVICE_ACCOUNT_ID:服务账号的 ID。
    • PROJECT_ID:在其中创建您的服务账号的项目。
    • BUCKET_NAME:您要向服务账号授予其访问权限的存储桶的名称。

    或者,如果您希望使用 Compute Engine 默认服务账号运行流水线,请运行 gcloud iam service-accounts list 命令来查找该账号的项目编号。

    gcloud iam service-accounts list
    

    Compute Engine 默认服务账号的名称如下:PROJECT_NUMBER-compute@developer.gserviceaccount.com

    运行以下命令,向 Compute Engine 默认服务账号授予读取和写入您在上一步创建的存储桶中的流水线工件的权限。

    gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \
    --member=serviceAccount:PROJECT_NUMBER-compute@developer.gserviceaccount.com \
    --role=roles/storage.objectUser
    

    替换以下值:

    • PROJECT_NUMBER:Compute Engine 默认服务账号的项目编号。
    • BUCKET_NAME:您要向服务账号授予其访问权限的存储桶的名称。

    详细了解如何控制对 Cloud Storage 存储桶的访问权限

创建使用 CMEK 的元数据存储区(可选)

请按照以下说明创建 CMEK 并设置使用此 CMEK 的 Vertex ML Metadata 元数据存储区。

  1. 使用 Cloud Key Management Service 配置客户管理的加密密钥。

  2. 使用以下 REST 调用来创建使用 CMEK 的项目默认元数据存储。

    在使用任何请求数据之前, 请进行以下替换:

    • LOCATION_ID:您的区域。
    • PROJECT_ID: 您的 [项目 ID](/resource-manager/docs/creating-managing-projects#identifiers)。 。
    • KEY_RING:加密密钥所在的 Cloud Key Management Service 密钥环的名称。
    • KEY_NAME:您要用于此元数据存储区的加密密钥的名称。

    HTTP 方法和网址:

    POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/metadataStores?metadata_store_id=default

    请求 JSON 正文:

    {
      "encryption_spec": {
        "kms_key_name": "projects/PROJECT_ID/locations/LOCATION_ID/keyRings/KEY_RING/cryptoKeys/KEY_NAME"
      },
    }
    

    如需发送您的请求,请展开以下选项之一:

    您应该收到类似以下内容的 JSON 响应:

    {
      "name": "projects/PROJECT_ID/locations/LOCATION_ID/operations/OPERATIONS_ID",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.aiplatform.v1.CreateMetadataStoreOperationMetadata",
        "genericMetadata": {
          "createTime": "2021-05-18T18:47:14.494997Z",
          "updateTime": "2021-05-18T18:47:14.494997Z"
        }
      }
    }