在 Agent Registry 中,端點代表目標網址 (通常是 REST API),代理程式會存取該網址。在 Agent Registry 中將這些目的地註冊為受管理代理功能元件,即可集中控管代理程式機群可連線的外部端點。
本文說明如何在登錄檔中明確註冊外部端點。
事前準備
開始之前,請先設定代理程式登錄。您需要專案 ID 才能執行這些工作。
如要使用本文中的 Google Cloud CLI 指令,請務必設定 gcloud CLI 環境。
必要的角色
如要取得在 Agent Registry 中註冊端點所需的權限,請要求管理員授予您專案的 Agent Registry API 編輯者 (roles/agentregistry.editor) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
註冊端點
由於端點是自訂的外部目的地,請使用手動註冊將端點新增至 Agent Registry:
控制台
前往 Google Cloud 控制台的「Agent Registry」:
在專案挑選器中,選取 Google Cloud 您設定 Agent Registry的專案。
選取「端點」分頁標籤。
按一下「新增端點」。
在「端點詳細資料」面板中,輸入顯示名稱、說明、地理區域和目的地網址。
(選用) 按一下這個面板中的「測試連線」,測試與目標網址的連線。
按一下 [儲存]。
gcloud
您可以使用 no-spec 的 endpoint-spec-type 建立 Service 資源。
註冊端點並定義介面連線詳細資料:
gcloud agent-registry services create ENDPOINT_NAME \
--project=PROJECT_ID \
--location=REGION \
--display-name="DISPLAY_NAME" \
--endpoint-spec-type=no-spec \
--interfaces=url=ENDPOINT_URL,protocolBinding=PROTOCOL
更改下列內容:
ENDPOINT_NAME:您要為端點指定的名稱,例如my-external-api。PROJECT_ID:專案 ID。REGION:登錄檔區域。DISPLAY_NAME:端點的易讀名稱。ENDPOINT_URL:目標網址,例如https://api.example.com/v1/data。PROTOCOL:介面的通訊協定繫結。有效值為http-json、grpc或jsonrpc。
Service 資源建立完成後,Agent Registry 會在消費者端自動產生唯讀的 Endpoint 資源,供代理程式和自動調度管理工具探索及使用。
Terraform
如要註冊外部端點,請使用 endpoint_spec 區塊設定 google_agent_registry_service 資源:
resource "google_agent_registry_service" "endpoint" {
location = "REGION"
service_id = "ENDPOINT_NAME"
display_name = "DISPLAY_NAME"
description = "An external REST API registered using Terraform."
interfaces {
url = "ENDPOINT_URL"
protocol_binding = "PROTOCOL"
}
endpoint_spec {
type = "NO_SPEC"
}
}
output "endpoint_resource_name" {
description = "The generated read-only Endpoint resource name."
value = google_agent_registry_service.endpoint.registry_resource
}
更改下列內容:
REGION:登錄檔區域。ENDPOINT_NAME:您要為端點指定的專屬名稱,例如my-external-api。DISPLAY_NAME:端點的易讀名稱。ENDPOINT_URL:目標網址,例如https://api.example.com/v1/data。PROTOCOL:介面的通訊協定繫結。有效值為HTTP_JSON、GRPC或JSONRPC。
註冊複合式 Google API 端點
在跨專案架構中,中央控管專案會代管 Agent Registry 和 Agent Gateway 等共用基礎架構,個別工作負載專案則會代管代理程式運算執行個體。
以輸出模式透過 Agent Gateway 轉送代理程式流量時,系統預設會封鎖傳出網路流量。如要讓工作負載專案中的代理程式與重要 Google Cloud API 通訊,您可以在中央控管專案中,將多個 API 介面分組為單一複合 Service 端點。
將介面分組到單一端點,可讓您管理整套核心 Google API 的單一 IAP 政策繫結,簡化政策管理作業。
如要註冊複合式 Google API 端點,請按照下列步驟操作:
gcloud
在中央控管專案中,使用多個介面網址註冊端點:
gcloud agent-registry services create SERVICE_NAME \
--project=CENTRAL_PROJECT_ID \
--location=REGION \
--display-name="DISPLAY_NAME" \
--description="DESCRIPTION" \
--endpoint-spec-type=no-spec \
--interfaces=protocolBinding=jsonrpc,url=API_URL \
--interfaces=protocolBinding=jsonrpc,url=ADDITIONAL_API_URL
更改下列內容:
SERVICE_NAME:服務的 ID,例如core-gapi-services。CENTRAL_PROJECT_ID:中央控管專案的專案 ID,用於代管 Agent Registry 和 Agent Gateway。REGION:閘道和登錄檔所在的區域。DISPLAY_NAME:使用者可自然閱讀的名稱,例如Core Google APIs。DESCRIPTION:簡短說明,例如Essential Google APIs for agent operations。API_URL:主要 Google API 的網址,例如https://telemetry.googleapis.com。ADDITIONAL_API_URL:針對代理程式所需的每個額外 Google API 網址或變體 (例如https://cloudresourcemanager.googleapis.com、https://iamcredentials.googleapis.com、https://agentregistry.googleapis.com,或是區域和 mTLS 變體 (如https://telemetry.mtls.googleapis.com)),重複使用--interfaces標記。
Terraform
如要使用 Terraform 註冊複合式 Google API 端點,請定義具有多個 interfaces 區塊的 google_agent_registry_service 資源:
resource "google_agent_registry_service" "core_gapi_services" {
project = "CENTRAL_PROJECT_ID"
location = "REGION"
service_id = "SERVICE_NAME"
display_name = "DISPLAY_NAME"
description = "DESCRIPTION"
endpoint_spec {
type = "NO_SPEC"
}
interfaces {
url = "API_URL"
protocol_binding = "JSONRPC"
}
# Add an interfaces block for each additional Google API URL
interfaces {
url = "ADDITIONAL_API_URL"
protocol_binding = "JSONRPC"
}
}
更改下列內容:
CENTRAL_PROJECT_ID:中央控管專案的專案 ID。REGION:登錄檔區域。SERVICE_NAME:服務 ID。DISPLAY_NAME:使用者可自然閱讀的名稱。DESCRIPTION:服務說明。API_URL:主要 Google API 的網址,例如https://telemetry.googleapis.com。ADDITIONAL_API_URL:針對代理程式所需的每個額外 Google API 網址或變體 (例如https://cloudresourcemanager.googleapis.com、https://iamcredentials.googleapis.com、https://agentregistry.googleapis.com,或是區域和 mTLS 變體 (如https://telemetry.mtls.googleapis.com)),重複interfaces區塊。
後續步驟
- 瞭解如何管理及探索已註冊的端點。
- 瞭解如何為已註冊的端點設定 IAM 輸出政策。