管理 Cloud Router

本文說明如何列出、更新、刪除 Cloud Router,以及取得其狀態。

事前準備

gcloud

如要使用本指南中的指令列範例,請按照下列步驟操作:

  1. 安裝或更新至最新版本的 Google Cloud CLI。
  2. 設定預設區域和可用區。

API

如要使用本指南中的 API 範例,請設定 API 存取權。

列出 Cloud Router

如要列出專案中的所有 Cloud Router,請按照下列步驟操作。

控制台

  1. 前往 Google Cloud 控制台的「Cloud Router」頁面。

    前往 Cloud Router

  2. 在「Cloud Routers」(Cloud Router) 頁面中,查看 Cloud Router 清單。

gcloud

請執行 list 指令。如要將清單限制在單一區域,請指定 --filter="region:(<var>REGION</var>)。

  gcloud compute routers list \
      --project=PROJECT_ID \
      [--filter="region:(REGION)]

更改下列內容:

  • PROJECT_ID:要列出 Cloud Router 的專案 ID
  • REGION:要列出路由器的區域,例如 asia-east1

輸出結果會與下列內容相似:

  NAME        REGION       NETWORK
  my-router   asia-east1   my-network

API

請使用 routers.aggregatedList 方法:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/aggregated/routers

將 PROJECT_ID 替換為要列出 Cloud Router 的專案 ID。

如要僅列出特定區域中的 Cloud Router,請使用 routers.list 方法:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers

更改下列內容:

  • PROJECT_ID:要列出 Cloud Router 的專案 ID
  • REGION:要列出 Cloud Router 的區域

更新 Cloud Router

如果 Cloud Router 與 NCC 閘道相關聯,請注意下列事項:

  • 無法更新「ncc_gateway」欄位。
  • patch 或 update 方法不接受 network 欄位做為要求主體的一部分。

gcloud

使用 gcloud compute routers update 指令:

gcloud compute routers update ROUTER_NAME
    --region=REGION

更改下列內容:

  • ROUTER_NAME:要更新的 Cloud Router 名稱
  • REGION:Cloud Router 所在的區域

API

請使用 routers.update 方法:

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME

更改下列內容:

  • PROJECT_ID:要列出 Cloud Router 的專案 ID
  • REGION:Cloud Router 所在的區域
  • ROUTER_NAME:要更新的 Cloud Router 名稱

取得 Cloud Router 狀態

gcloud

使用 gcloud compute routers get-status 指令。

gcloud compute routers get-status ROUTER_NAME \
    --project=PROJECT_ID \
    --region=REGION

更改下列內容:

  • ROUTER_NAME:要取得狀態的 Cloud Router 名稱
  • PROJECT_ID:Cloud Router 所屬的專案 ID
  • REGION:Cloud Router 所在的區域

API

使用 routers.getRouterStatus 方法,並將要求主體留空:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME/getRouterStatus

更改下列內容:

  • PROJECT_ID:Cloud Router 所屬的專案 ID
  • REGION:Cloud Router 所在的區域
  • ROUTER_NAME:要取得狀態的 Cloud Router 名稱

刪除 Cloud Router

刪除 Cloud Router 前,請先確認沒有其他資源 (例如 Cloud VPN 通道或 VLAN 連結) 正在使用該路由器。您必須先刪除相關聯的資源,才能刪除 Cloud Router。不過,您不需先移除 BGP 工作階段,即可刪除 Cloud Router。

如要刪除 Cloud Router,請按照下列步驟操作。

控制台

  1. 前往 Google Cloud 控制台的「Cloud Router」頁面。

    前往 Cloud Router

  2. 找出要刪除的 Cloud Router,然後勾選旁邊的核取方塊。

  3. 按一下 「Delete」(刪除)。

gcloud

請執行 delete 指令。指定要刪除的 Cloud Router 名稱和位置。

gcloud compute routers delete ROUTER_NAME \
    --project=PROJECT_ID \
    --region=REGION

更改下列內容:

  • ROUTER_NAME:要刪除的 Cloud Router 名稱

  • PROJECT_ID:要刪除的 Cloud Router 所在專案 ID

  • REGION:Cloud Router 所在的區域

輸出結果會與下列內容相似:

Deleted [https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/asia-east1/routers/ROUTER_NAME].

API

請使用 routers.delete 方法:

DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME

更改下列內容:

  • PROJECT_ID:要刪除的 Cloud Router 所在專案 ID
  • REGION:Cloud Router 所在的區域
  • ROUTER_NAME:Cloud Router 的名稱

後續步驟

  • 如要查看 Cloud Router 的設定、BGP 工作階段,以及 Cloud Router advertise 的路由,請參閱「查看路由器詳細資料」。
  • 如要排解使用 Cloud Router 時遇到的問題,請參閱「疑難排解」。