本指南介绍了如何为 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 搭配使用。
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, Compute Engine, and Cloud Storage APIs.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Update and install
gcloud
components:gcloud components update
gcloud components install beta -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, Compute Engine, and Cloud Storage APIs.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Update and install
gcloud
components:gcloud components update
gcloud components install beta - 如果您不是项目所有者,并且没有 Project IAM Admin (
roles/resourcemanager.projectIamAdmin
) 角色,请让所有者为您授予 Compute Network Admin (roles/compute.networkAdmin
) 角色,该角色包括管理网络资源所需的角色。 - 将网络宿主 Google Cloud 项目的 Compute Network Admin 角色分配给您在其中使用 Vertex AI Training 服务的项目的 AI Platform Service Agent 账号。
设置 VPC 网络和子网
在本部分中,您可以使用现有的 VPC 网络,或者按照配置步骤创建新的 VPC 网络(如果您没有现有网络)。
-
gcloud compute networks create NETWORK \ --subnet-mode=custom
将 NETWORK 替换为 VPC 网络的名称。
-
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 只能访问在必需的 PRIMARY_RANGE 中指定的 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。
配置防火墙规则
在使用方 VPC 中应用入站防火墙规则,以便从计算和本地端点与 Private Service Connect 接口网络连接子网进行通信。
配置防火墙规则是可选操作。不过,我们建议您设置常见的防火墙规则,如以下示例所示。
创建一条防火墙规则,以允许通过 TCP 端口 22 进行 SSH 访问:
gcloud compute firewall-rules create NETWORK-firewall1 \ --network NETWORK \ --allow tcp:22
创建一条允许 TCP 端口 443 上的 HTTPS 流量的防火墙规则:
gcloud compute firewall-rules create NETWORK-firewall2 \ --network NETWORK \ --allow tcp:443
创建一条允许 ICMP 流量(例如 ping 请求)的防火墙规则:
gcloud compute firewall-rules create NETWORK-firewall3 \ --network NETWORK \ --allow tcp:icmp
问题排查
本部分列出了使用 Vertex AI 配置 Private Service Connect 接口时的一些常见问题。
- 将 Vertex AI 配置为使用共享 VPC 网络时,请在 Vertex AI 资源中指定网络连接。例如,在
CustomJob
创建请求中,请使用以下格式:"projects/YOUR_SHARED_VPC_HOST_PROJECT_NUMBER/regions/REGION/networkAttachments/NETWORK_ATTACHMENT_NAME"
- 如果您指定 Vertex AI 要使用的共享 VPC 网络,请确保服务项目中的 AI Platform Service Agent 在您的 VPC 宿主项目中具有
compute.networkUser
角色。 - 除非提供方 (Vertex AI) 删除已分配的资源,否则无法删除网络连接。如需启动删除流程,您必须与 Vertex AI 支持团队联系。
后续步骤
- 了解如何为Vertex AI 上的 Ray 使用 Private Service Connect 接口出站流量。
- 了解如何使用 Private Service Connect 接口出站流量进行自定义训练。
- 了解如何为 Vertex AI Pipelines 使用 Private Service Connect 接口出站流量。