为 Vertex AI 资源设置 Private Service Connect 接口

本指南介绍了如何为 Vertex AI 资源设置 Private Service Connect 接口

您可以为 Vertex AI 中的某些资源配置 Private Service Connect 接口连接,这些资源包括:

VPC 对等互连连接不同,Private Service Connect 接口连接可以是传递性的,在使用方 VPC 网络中需要更少的 IP 地址。这样一来,您就可以更灵活地连接到 Google Cloud 项目和本地环境中的其他 VPC 网络。

建议已熟悉 Google Cloud 网络概念的网络管理员阅读本指南。

目标

本指南包含以下任务:

  • 配置提供方 VPC 网络、子网和网络连接。
  • 向 Google Cloud 网络宿主项目添加防火墙规则。
  • 创建 Vertex AI 资源,并指定网络连接以使用 Private Service Connect 接口。

准备工作

按照以下说明创建或选择 Google Cloud 项目,并将其配置为与 Vertex AI 和 Private Service Connect 搭配使用。

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI, Compute Engine, and Cloud Storage APIs.

    Enable the APIs

  5. Install the Google Cloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    gcloud init
  8. After initializing the gcloud CLI, update it and install the required components:

    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.

    Go to project selector

  10. Make sure that billing is enabled for your Google Cloud project.

  11. Enable the Vertex AI, Compute Engine, and Cloud Storage APIs.

    Enable the APIs

  12. Install the Google Cloud CLI.

  13. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  14. To initialize the gcloud CLI, run the following command:

    gcloud init
  15. After initializing the gcloud CLI, update it and install the required components:

    gcloud components update
    gcloud components install beta
  16. 如果您不是项目所有者,并且没有 Project IAM Admin (roles/resourcemanager.projectIamAdmin) 角色,请让项目所有者为您授予 Compute Network Admin (roles/compute.networkAdmin) 角色,该角色包括管理网络资源所需的角色。
  17. 将网络宿主 Google Cloud 项目的 Compute Network Admin 角色分配给您在其中使用 Vertex AI Training 服务的项目的 AI Platform Service Agent 账号。
  18. 设置 VPC 网络和子网

    在本部分中,您可以使用现有 VPC 网络,也可以按照配置步骤创建新的 VPC 网络(如果您没有现有网络)。

    1. 创建 VPC 网络:

      gcloud compute networks create NETWORK \
          --subnet-mode=custom
      

      NETWORK 替换为 VPC 网络的名称。

    2. 创建子网:

      gcloud compute networks subnets create SUBNET_NAME \
          --network=NETWORK \
          --range=PRIMARY_RANGE \
          --region=REGION
      

      替换以下内容:

      • SUBNET_NAME:子网的名称。
      • PRIMARY_RANGE:新子网的主要 IPv4 范围(采用 CIDR 表示法)。如需了解详情,请参阅 IPv4 子网范围

        Vertex AI 需要 /28 子网。

        Vertex AI 只能访问可从指定 NETWORK 路由的 RFC 1918 范围。如需查看有效的 RFC 1918 范围的列表,请参阅有效 IPv4 范围。Vertex AI 无法访问以下非 RFC 1918 范围:

        • 100.64.0.0/10
        • 192.0.0.0/24
        • 192.0.2.0/24
        • 198.18.0.0/15
        • 198.51.100.0/24
        • 203.0.113.0/24
        • 240.0.0.0/4
      • REGION:在其中创建新子网的 Google Cloud 区域。

    创建网络连接

    在共享 VPC 部署中,在宿主项目中创建用于网络连接的子网,然后在服务项目中创建 Private Service Connect 网络连接。

    以下示例展示了如何创建可手动接受连接的网络连接

       gcloud compute network-attachments create NETWORK_ATTACHMENT_NAME \
           --region=REGION \
           --connection-preference=ACCEPT_MANUAL \
           --subnets=SUBNET_NAME
    

    NETWORK_ATTACHMENT_NAME 替换为网络连接的名称。

    Vertex AI 服务代理所需的角色

    在您创建网络连接的项目中,验证是否已向同一项目的 Vertex AI 服务代理授予 compute.networkAdmin 角色。如果此项目与您使用 Vertex AI 的服务项目不同,您需要提前在此项目中启用 Vertex AI API。

    如果您指定 Vertex AI 要使用的共享 VPC 网络,并在服务项目中创建网络连接,请务必向您使用 Vertex AI 的服务项目中的 Vertex AI 服务代理授予 VPC 宿主项目的 compute.networkUser 角色。

    配置防火墙规则

    在使用方 VPC 中应用入站防火墙规则,以便从计算和本地端点与 Private Service Connect 接口网络连接子网进行通信。

    配置防火墙规则是可选操作。不过,我们建议您设置常见的防火墙规则,如以下示例所示。

    1. 创建一条防火墙规则,允许通过 TCP 端口 22 进行 SSH 访问:

      gcloud compute firewall-rules create NETWORK-firewall1 \
          --network NETWORK \
          --allow tcp:22
      
    2. 创建一条允许 TCP 端口 443 上的 HTTPS 流量的防火墙规则:

      gcloud compute firewall-rules create NETWORK-firewall2 \
          --network NETWORK \
          --allow tcp:443
      
    3. 创建一条允许 ICMP 流量(例如 ping 请求)的防火墙规则:

      gcloud compute firewall-rules create NETWORK-firewall3 \
          --network NETWORK \
          --allow icmp
      

    设置专用 DNS 对等互连

    为了使配置了 PSC-I 的 Vertex AI Training 作业能够解析客户管理的 Cloud DNS 区域中的专用 DNS 记录,Vertex AI API 提供了一种用户可配置的机制,用于指定应进行对等互连的 DNS 网域。您需要进行以下其他配置。

    1. 将 DNS Peer(roles/dns.peer) 角色分配给您在其中使用 Vertex AI Training 服务的项目的 AI Platform Service Agent 账号。 如果您指定 Vertex AI 要使用的共享 VPC 网络,并在服务项目中创建网络连接,请务必在 VPC 宿主项目中向您使用 Vertex AI 的服务项目中的 AI Platform Service Agent 授予 DNS Peer(roles/dns.peer) 角色。

    2. 创建一条允许所有 ICMP、TCP 和 UDP 流量的防火墙规则(可选):

      !gcloud compute firewall-rules create NETWORK-firewall4 \
          --network NETWORK
          --allow tcp:0-65535,udp:0-65535,icmp
          --source-ranges IP_RANGES
      
    3. 设置专用 DNS 区域,以进行 DNS 解析和流量路由。 如需将 DNS 记录添加到专用 DNS 区域,请参阅添加资源记录集

    后续步骤