本指南介绍了如何为 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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, Compute Engine, and Cloud Storage APIs.
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
-
初始化 gcloud CLI 后,对其进行更新并安装所需组件:
gcloud components update gcloud components install beta
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, Compute Engine, and Cloud Storage APIs.
-
Install the Google Cloud CLI.
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
-
初始化 gcloud CLI 后,对其进行更新并安装所需组件:
gcloud components update gcloud components install beta
- 如果您不是项目所有者,并且没有 Project IAM Admin (
roles/resourcemanager.projectIamAdmin
) 角色,请让项目所有者为您授予包含compute.networkAttachments.update
权限的 IAM 角色(例如 Compute Network Admin (roles/compute.networkAdmin
) 角色),以便您管理网络资源。 - 将网络宿主 Google Cloud 项目的 Compute Network Admin 角色分配给您在其中使用 Vertex AI Training 服务的项目的 AI Platform Service Agent 账号。
-
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 只能访问可从指定 NETWORK 路由的 RFC 1918 范围。也就是说,网络连接子网不能是非 RFC 1918 IP 范围。如需查看有效的 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 区域。
创建一条允许通过 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 icmp
将 DNS
Peer(roles/dns.peer)
角色分配给您在其中使用 Vertex AI Training 服务的项目的 AI Platform Service Agent 账号。如果您指定 Vertex AI 要使用的共享 VPC 网络,并在服务项目中创建网络连接,请向您使用 Vertex AI 的服务项目中的 AI Platform Service Agent 授予 VPC 宿主项目中的 DNSPeer(roles/dns.peer)
角色。创建一条允许所有 ICMP、TCP 和 UDP 流量的防火墙规则(可选):
gcloud compute firewall-rules create NETWORK-firewall4 \ --network NETWORK --allow tcp:0-65535,udp:0-65535,icmp --source-ranges IP_RANGES
设置专用 DNS 区域,以解析 DNS 并路由流量。如需将 DNS 记录添加到专用 DNS 区域,请参阅添加资源记录集。
- 了解如何为Vertex AI 上的 Ray 使用 Private Service Connect 接口出站流量。
- 了解如何使用 Private Service Connect 接口出站流量进行自定义训练。
- 了解如何为 Vertex AI Pipelines 使用 Private Service Connect 接口出站流量。
设置 VPC 网络和子网
如果您没有现有网络,请按照相应配置步骤创建新的 VPC 网络。
创建网络连接
在共享 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 接口网络连接子网进行通信。
配置防火墙规则是可选操作。不过,我们建议您设置常用的防火墙规则,如以下示例所示。
设置专用 DNS 对等互连
为了使配置了 PSC-I 的 Vertex AI Training 作业能够解析客户管理的 Cloud DNS 区域中的专用 DNS 记录,Vertex AI API 提供了一种用户可配置的机制,用于指定应与 Google 内部资源进行对等互连的 DNS 网域。您需要进行以下额外配置。
问题排查
本部分介绍了为 Vertex AI 配置 Private Service Connect 时的一些常见问题。
为 Vertex AI 配置共享 VPC 时,请在您使用 Vertex AI 的服务项目中创建网络连接。此方法可确保在正确的项目中启用必要的权限和 API,从而有助于避免某些错误消息,例如“请确保已为项目启用 Vertex AI API”消息。