使用 Cloud DNS 轉送政策和內部 TCP/UDP 負載平衡器健康狀態檢查的多區域容錯移轉

1. 簡介

上次更新時間:2022 年 9 月 22 日

什麼是 DNS 轉送政策

使用者可以透過 Cloud DNS 轉送政策,根據權重、地理位置或健康狀態檢查等特定條件,設定 DNS 流量導引。

Cloud DNS 支援下列路由政策:

  • 加權循環制轉送政策
  • 地理位置轉送政策
  • 設有地理圍欄的路由政策
  • 容錯移轉轉送政策

在本實驗室中,您將設定並測試容錯移轉路由政策。

容錯移轉轉送政策

Cloud DNS 支援對已啟用全域存取權的內部 TCP/UDP 負載平衡器進行健康狀態檢查。使用容錯移轉轉送政策時,您可以為資源記錄設定主要和備用 IP。正常運作下,Cloud DNS 會以主要集合中佈建的 IP 位址回應查詢。如果主要集合中的所有 IP 位址都失敗 (健康狀態變更為不良),Cloud DNS 會開始提供備份集合中的 IP 位址。

安全狀態檢查

DNS 路由政策會依據原生內部負載平衡器統一健康狀態檢查(UHC) 判斷。如果後端健康狀態良好,且比例達到 20% 以上,內部負載平衡器就會視為健康狀態良好。內部 TCP/UDP 和內部 HTTP(S) 負載平衡器的健康狀態檢查會提供不同資訊。如果是內部 HTTP(S) 負載平衡器,UHC 會提供所有 Envoy Proxy 的健康狀態,但如果是內部 TCP/UDP 負載平衡器,Cloud DNS 會直接從個別後端執行個體取得健康狀態信號。如要瞭解健康檢查的詳細資訊,請參閱這篇文章

建構項目

在本程式碼研究室中,您將建構在 2 個區域中執行的網站,並將容錯移轉 DNS 路由政策與該網站建立關聯。設定內容包括:

運作中的資源 -

  • REGION_1 中的 L4 內部負載平衡器
  • 在 REGION_1 中執行 Apache 網路伺服器的 VM

備份資源 -

  • REGION_2 中的 L4 內部負載平衡器
  • 在 REGION_2 中執行 Apache 網路伺服器的 VM

設定如下所示:

d0a91d3d3698f544.png

課程內容

  • 如何建立容錯移轉路由政策
  • 觸發 DNS 容錯移轉
  • 如何將流量逐步轉移至備份集

軟硬體需求

  • 具備 DNS 基本知識
  • Google Compute Engine 的基本知識
  • L4 內部負載平衡器的基本知識

2. 設定和需求

  1. 登入 Google Cloud 控制台,然後建立新專案或重複使用現有專案。如果沒有 Gmail 或 Google Workspace 帳戶,請先建立帳戶

b35bf95b8bf3d5d8.png

a99b7ace416376c4.png

bd84a6d3004737c5.png

  • 專案名稱是這個專案參與者的顯示名稱。這是 Google API 未使用的字元字串。你隨時可以更新該位置資訊。
  • 專案 ID 在所有 Google Cloud 專案中不得重複,且設定後即無法變更。Cloud 控制台會自動產生不重複的字串,通常您不需要在意這個字串。在大多數程式碼研究室中,您需要參照專案 ID (通常會標示為 PROJECT_ID)。如果您不喜歡產生的 ID,可以產生另一個隨機 ID。你也可以嘗試自訂名稱,看看是否可用。完成這個步驟後就無法變更,且專案期間都會維持這個設定。
  • 請注意,部分 API 會使用第三個值,也就是「專案編號」。如要進一步瞭解這三種值,請參閱說明文件
  1. 接著,您需要在 Cloud 控制台中啟用帳單,才能使用 Cloud 資源/API。完成本程式碼研究室的費用應該不高,甚至完全免費。如要關閉資源,避免產生本教學課程以外的費用,您可以刪除自己建立的資源,或刪除整個專案。Google Cloud 新使用者可參加價值$300 美元的免費試用計畫。

啟動 Cloud Shell

雖然可以透過筆電遠端操作 Google Cloud,但在本程式碼研究室中,您將使用 Google Cloud Shell,這是可在雲端執行的指令列環境。

Google Cloud 控制台中,點選右上工具列的 Cloud Shell 圖示:

55efc1aaa7a4d3ad.png

佈建並連線至環境的作業需要一些時間才能完成。完成後,您應該會看到如下的內容:

7ffe5cbb04455448.png

這部虛擬機器搭載各種您需要的開發工具,並提供永久的 5GB 主目錄,而且可在 Google Cloud 運作,大幅提升網路效能並強化驗證功能。您可以在瀏覽器中完成本程式碼研究室的所有作業。您不需要安裝任何軟體。

3. Google Cloud SDK 版本

截至本文撰寫時間為止,401.0.0 是最新版的 Google Cloud SDK。本實驗室中的所有指令都經過測試,可搭配最新版 Google Cloud SDK 使用。繼續操作前,請確認 Cloud Shell 使用的是最新版 SDK。

檢查 SDK 版本

使用 gcloud version 指令檢查 SDK 版本。在 Cloud Shell 中執行下列指令:

指令

gcloud version | grep "Google Cloud SDK"

輸出內容範例

Google Cloud SDK 401.0.0

後續步驟

  1. 如果 SDK 版本為 401.0.0 以上,請跳至下一節。
  2. 如果 SDK 版本低於 401.0.0,請執行下列指令更新 SDK。

選用指令

sudo apt-get update && sudo apt-get install google-cloud-sdk

4. 事前準備

開始部署上述架構前,請先確認 Cloud Shell 設定正確無誤,並啟用所有必要 API。

設定專案 ID

在 Cloud Shell 中,確認專案 ID 已設定完畢。如果 Cloud Shell 提示與下方輸出內容類似,且您不打算變更專案 ID,則可以跳至下一個步驟 (設定環境變數)。

USER@cloudshell:~ (PROJECT_ID)$

如要變更專案 ID,請使用下列指令,Cloud Shell 提示會從 (PROJECT_ID) 變更為 (YOUR-PROJECT-ID)

選用指令

gcloud config set project [YOUR-PROJECT-ID]

輸出內容範例

Updated property [core/project].
USER@cloudshell:~ (YOUR-PROJECT-ID)$

設定環境變數

設定環境變數

我們將使用 export 指令設定環境變數。在 Cloud Shell 中執行下列指令:

指令

export REGION_1=us-west1
export REGION_1_ZONE=us-west1-a
export REGION_2=us-east4
export REGION_2_ZONE=us-east4-a

驗證

環境變數設定完成後,請使用 echo 指令進行驗證。每個指令的輸出內容都應該是我們使用 export 指令設定的值。在 Cloud Shell 中執行下列指令:

指令

echo $REGION_1
echo $REGION_1_ZONE
echo $REGION_2
echo $REGION_2_ZONE

啟用所有必要服務

使用 gcloud services enable 指令啟用 Compute 和 DNS API。在 Cloud Shell 中執行下列指令:

啟用 Compute API

指令

gcloud services enable compute.googleapis.com

啟用 DNS API

指令

gcloud services enable dns.googleapis.com

驗證

服務啟用後,請使用 gcloud services list 指令列出所有已啟用的 API,藉此進行驗證。

指令

gcloud services list | grep -E 'compute|dns'

輸出內容範例

NAME: compute.googleapis.com
NAME: dns.googleapis.com

5. 建立虛擬私有雲網路、子網路和防火牆規則

在本節中,我們將建立虛擬私有雲網路、兩個子網路 (每個區域各一個),以及必要的防火牆規則。

建立虛擬私有雲網路

使用 gcloud compute networks create 指令建立 VPC 網路。我們將子網路模式設為自訂,因為我們會在下一個步驟中建立自己的子網路。在 Cloud Shell 中執行下列指令。

指令

gcloud compute networks create my-vpc --subnet-mode custom

建立子網路

使用 gcloud compute networks subnets create 指令建立兩個子網路,分別位於 REGION_1 和 REGION_2。在 Cloud Shell 中執行下列指令:

REGION_1 子網路

指令

gcloud compute networks subnets create ${REGION_1}-subnet \
--network my-vpc \
--range 10.1.0.0/24 \
--region $REGION_1

REGION_2 子網路

指令

gcloud compute networks subnets create ${REGION_2}-subnet \
--network my-vpc \
--range 10.2.0.0/24 \
--region $REGION_2

建立防火牆規則

您需要允許來自 VPC 子網路和負載平衡器健康檢查 IP 範圍的通訊埠 80 流量。

此外,您也需要建立防火牆規則,允許用戶端 VM 上的 SSH 流量。

使用 gcloud compute firewall-rules create 指令建立防火牆規則。在 Cloud Shell 中執行下列指令:

允許通訊埠 80 上的流量

指令

gcloud compute firewall-rules create allow-http-lb-hc \
--allow tcp:80 --network my-vpc \
--source-ranges 10.1.0.0/24,10.2.0.0/24,35.191.0.0/16,130.211.0.0/22 \
--target-tags=allow-http

在用戶端 VM 上允許 SSH 流量

指令

gcloud compute firewall-rules create allow-ssh \
--allow tcp:22 --network my-vpc \
--source-ranges 0.0.0.0/0 \
--target-tags=allow-ssh

6. 建立 Cloud NAT

您需要在兩個區域中都設定 Cloud NAT 閘道,私人 VM 才能從網際網路下載及安裝套件。

  • 網路伺服器 VM 必須下載並安裝 Apache 網路伺服器。
  • 用戶端 VM 必須下載並安裝 dnsutils 套件,以供測試使用。

每個 Cloud NAT 閘道都與單一 VPC 網路、區域和 Cloud Router 相關聯。因此,在建立 NAT 閘道之前,我們需要在每個區域中建立 Cloud Router。

建立 Cloud Router

使用 gcloud compute routers create 指令在 us-west1 和 us-east4 地區建立 Cloud Router。在 Cloud Shell 中執行下列指令。

Region_1 Cloud Router

指令

gcloud compute routers create "${REGION_1}-cloudrouter" \
--region $REGION_1 --network=my-vpc --asn=65501

Region_2 Cloud Router

指令

gcloud compute routers create "${REGION_2}-cloudrouter" \
--region $REGION_2 --network=my-vpc --asn=65501

建立 NAT 閘道

使用 gcloud compute routers nat create 指令在 us-west1 和 us-east4 地區建立 NAT 閘道。在 Cloud Shell 中執行下列指令。

Region_1 NAT 閘道

指令

gcloud compute routers nats create "${REGION_1}-nat-gw" \
--router="${REGION_1}-cloudrouter" \
--router-region=$REGION_1 \
--nat-all-subnet-ip-ranges --auto-allocate-nat-external-ips

Region_2 NAT 閘道

指令

gcloud compute routers nats create "${REGION_2}-nat-gw" \
--router="${REGION_2}-cloudrouter" \
--router-region=$REGION_2 \
--nat-all-subnet-ip-ranges --auto-allocate-nat-external-ips

7. 建立 Compute Engine VM

在本節中,您將建立網路伺服器、網路伺服器的非代管執行個體群組,以及用戶端 VM。

建立網路伺服器 VM

使用 gcloud compute instances create 指令建立網路伺服器。我們需要建立兩個網頁伺服器,分別位於 REGION_1 和 REGION_2。我們使用開機指令碼在網路伺服器上安裝及設定 Apache。

REGION_1 Web Server

在 Cloud Shell 中執行下列指令

指令

gcloud compute instances create "${REGION_1}-instance" \
--image-family=debian-11 --image-project=debian-cloud \
--zone=$REGION_1_ZONE \
--network-interface=network=my-vpc,subnet=${REGION_1}-subnet,no-address \
--tags=allow-http \
--metadata=startup-script='#! /bin/bash
    apt-get update
    apt-get install apache2 -y
    a2ensite default-ssl
    a2enmod ssl
    vm_hostname="$(curl -H "Metadata-Flavor:Google" \
    http://169.254.169.254/computeMetadata/v1/instance/name)"
    echo "Page served from: $vm_hostname" | \
    tee /var/www/html/index.html
    systemctl restart apache2'

REGION_2 Web Server

在 Cloud Shell 中執行下列指令

指令

gcloud compute instances create "${REGION_2}-instance" \
--image-family=debian-11 --image-project=debian-cloud \
--zone=$REGION_2_ZONE \
--network-interface=network=my-vpc,subnet=${REGION_2}-subnet,no-address \
--tags=allow-http \
--metadata=startup-script='#! /bin/bash
    apt-get update
    apt-get install apache2 -y
    a2ensite default-ssl
    a2enmod ssl
    vm_hostname="$(curl -H "Metadata-Flavor:Google" \
    http://169.254.169.254/computeMetadata/v1/instance/name)"
    echo "Page served from: $vm_hostname" | \
    tee /var/www/html/index.html
    systemctl restart apache2'

建立非代管執行個體群組

在本節中,我們將建立兩個非代管執行個體群組。我們會在下一節中使用這些執行個體群組,設定 ILB 後端服務。建立執行個體群組後,我們會將網路伺服器 VM 新增至這些群組。

建立非代管執行個體群組

使用 gcloud compute instance-groups unmanaged create 指令建立兩個非代管執行個體群組,分別用於 us-west1 和 us-east4 網路伺服器。

Region_1 執行個體群組

指令

gcloud compute instance-groups unmanaged create \
"${REGION_1}-instance-group" --zone=$REGION_1_ZONE

Region_2 執行個體群組

指令

gcloud compute instance-groups unmanaged create \
"${REGION_2}-instance-group" --zone=$REGION_2_ZONE

將 VM 新增至執行個體群組

使用 gcloud compute instance-groups unmanaged add-instances 指令,將執行個體新增至我們剛建立的執行個體群組。將 REGION_1 網路伺服器新增至 REGION_1 執行個體群組,並將 REGION_2 網路伺服器新增至 REGION_2 執行個體群組

Region_1 執行個體群組

指令

gcloud compute instance-groups unmanaged add-instances \
"${REGION_1}-instance-group" --instances $REGION_1-instance \
--zone=$REGION_1_ZONE

Region_2 執行個體群組

指令

gcloud compute instance-groups unmanaged add-instances \
"${REGION_2}-instance-group" --instances $REGION_2-instance \
--zone=$REGION_2_ZONE

建立用戶端 VM

我們會使用這個 VM 執行測試,並驗證 DNS 設定。我們使用開機指令碼安裝 dnsutils 套件。在 Cloud Shell 中執行下列指令。

指令

gcloud compute instances create client-instance --image-family=debian-11 \
--image-project=debian-cloud \
--zone=$REGION_1_ZONE \
--network-interface=network=my-vpc,subnet=${REGION_1}-subnet,no-address \
--tags=allow-ssh \
--metadata=startup-script='#! /bin/bash
    apt-get update
    apt-get install dnsutils -y'

8. 建立 L4 內部負載平衡器

如要建立 L4 ILB,我們需要建立健康狀態檢查、後端服務和轉送規則。

建立健康狀態檢查

使用 gcloud compute health-checks create 指令建立健康狀態檢查。我們正在建立基本的 HTTP 健康狀態檢查,目標通訊埠為通訊埠 80。在 Cloud Shell 中執行下列指令:

指令

gcloud compute health-checks create http http-hc --port 80

設定後端服務

使用 gcloud compute backend-services create 指令建立後端服務。建立後端服務後,我們將使用 gcloud compute backend-services add-backend 指令,將非代管執行個體群組新增至後端服務。在 Cloud Shell 中執行下列指令。

建立後端服務

指令

gcloud compute backend-services create $REGION_1-backend-service \
--load-balancing-scheme=INTERNAL --protocol=TCP \
--health-checks=http-hc --region=$REGION_1
gcloud compute backend-services create $REGION_2-backend-service \
--load-balancing-scheme=INTERNAL --protocol=TCP \
--health-checks=http-hc --region=$REGION_2

新增後端

指令

gcloud compute backend-services add-backend $REGION_1-backend-service \
--instance-group=$REGION_1-instance-group \
--region=$REGION_1 \
--instance-group-zone=$REGION_1_ZONE
gcloud compute backend-services add-backend $REGION_2-backend-service \
--instance-group=$REGION_2-instance-group \
--region=$REGION_2 \
--instance-group-zone=$REGION_2_ZONE

建立轉送規則

使用 gcloud compute forwarding-rules create 指令在兩個區域中建立轉送規則。在 Cloud Shell 中執行下列指令:

REGION_1 轉送規則

指令

gcloud compute forwarding-rules create $REGION_1-ilb \
    --region=$REGION_1 \
    --load-balancing-scheme=internal \
    --network=my-vpc \
    --subnet=$REGION_1-subnet \
    --ip-protocol=TCP \
    --ports=80 \
    --backend-service=$REGION_1-backend-service \
    --backend-service-region=$REGION_1 \
    --allow-global-access

REGION_2 轉送規則

gcloud compute forwarding-rules create $REGION_2-ilb \
    --region=$REGION_2 \
    --load-balancing-scheme=internal \
    --network=my-vpc \
    --subnet=$REGION_2-subnet \
    --ip-protocol=TCP \
    --ports=80 \
    --backend-service=$REGION_2-backend-service \
    --backend-service-region=$REGION_2 \
    --allow-global-access

9. 設定 DNS

在本節中,我們將建立私人區域和 DNS 記錄集,並採用容錯移轉轉送政策。

建立私人 DNS 區域

使用 gcloud dns managed-zones create 指令為 example.com 建立私人區域。我們會使用這個區域建立資源記錄集,並採用容錯移轉轉送政策。在 Cloud Shell 中執行下列指令

指令

gcloud dns managed-zones create example-com \
--dns-name example.com. --description="My private zone" \
--visibility=private --networks my-vpc 

建立採用容錯移轉路由政策的 DNS 記錄

使用 gcloud dns record-sets create 指令建立 DNS 記錄,並採用容錯移轉轉送政策。主要目標是 REGION_1 中的負載平衡器。Cloud DNS 僅支援以地理位置為基礎的備份目標,備份集是以 REGION_2 負載平衡器為目標的地理位置政策,適用於 REGION_1 和 REGION_2。在 Cloud Shell 中執行下列指令:

指令

gcloud dns record-sets create failover.example.com --ttl 5 --type A \
--routing-policy-type=FAILOVER \
--routing-policy-primary-data=$REGION_1-ilb \
--routing-policy-backup-data="${REGION_1}=${REGION_2}-ilb;${REGION_2}=${REGION_2}-ilb" \
--routing-policy-backup-data-type=GEO \
--zone=example-com \
--enable-health-checking

輸出內容範例

NAME: failover.example.com.
TYPE: A
TTL: 5
DATA: Primary: "10.1.0.4, 80, tcp, https://www.googleapis.com/compute/v1/projects/my-clouddns-codelab/global/networks/my-vpc, my-clouddns-codelab, us-west1, regionalL4ilb" Backup: us-west1: "10.2.0.3, 80, tcp, https://www.googleapis.com/compute/v1/projects/my-clouddns-codelab/global/networks/my-vpc, my-clouddns-codelab, us-east4, regionalL4ilb";us-east4: "10.2.0.3, 80, tcp, https://www.googleapis.com/compute/v1/projects/my-clouddns-codelab/global/networks/my-vpc, my-clouddns-codelab, us-east4, regionalL4ilb"

10. 測試 DNS 解析

在測試容錯移轉設定前,請先記下兩個內部負載平衡器的 IP 位址。在 Cloud Shell 中執行下列指令。

指令

gcloud compute forwarding-rules list --filter="name:($REGION_1-ilb $REGION_2-ilb)"

輸出內容範例

在本例中,us-west1-ilb 的 IP 位址為 10.1.0.4us-east4-ilb 的 IP 位址為 10.2.0.3

NAME: us-west1-ilb
REGION: us-west1
IP_ADDRESS: 10.1.0.4
IP_PROTOCOL: TCP
TARGET: us-west1/backendServices/us-west1-backend-service

NAME: us-east4-ilb
REGION: us-east4
IP_ADDRESS: 10.2.0.3
IP_PROTOCOL: TCP
TARGET: us-east4/backendServices/us-east4-backend-service

現在我們要登入用戶端執行個體,並測試 DNS 解析。在網頁控制台中,前往「Compute Engine | VM 執行個體」

5c824940bf414501.png

按一下「SSH」按鈕,從控制台登入用戶端執行個體。

b916eb32c60a4156.png

現在我們已進入用戶端 VM,請使用 dig 指令解析 failover.example.com 網域名稱。

迴圈設定為執行指令十次,睡眠計時器為 6 秒。

指令

for i in {1..10}; do echo $i; dig failover.example.com +short; sleep 6; done

由於 DNS 記錄的存留時間設為 5 秒,因此已新增 6 秒的休眠計時器。休眠計時器可確保每個 DNS 要求都會取得未快取的 DNS 回應。執行過程大約需要一分鐘。

在輸出內容中,您會看到資源記錄主要集合中的負載平衡器 IP 位址。在我們的設定中,這會是 us-west1 區域中負載平衡器的 IP。

11. 測試容錯移轉

我們將從 REGION_1 VM 移除網路標記,模擬容錯移轉。這樣會封鎖通訊埠 80 的存取權,導致健康狀態檢查開始失敗。

移除網路標記

使用 gcloud compute instances remove-tags 指令從 VM 移除網路標記。在 Cloud Shell 中執行下列指令

指令

gcloud compute instances remove-tags $REGION_1-instance \
--zone=$REGION_1_ZONE --tags=allow-http

健康狀態檢查將在 10 秒後失敗。再次執行 DNS 解析測試。

DNS 解析

在用戶端執行個體中執行下列指令

指令

for i in {1..10}; do echo $i; dig failover.example.com +short; sleep 6; done

在輸出內容中,您會看到資源記錄備份集中的負載平衡器 IP 位址。在我們的設定中,這會是 us-east4 地區的負載平衡器 IP。

12. 測試流量緩慢增加

根據預設,容錯移轉政策會針對所有 DNS 要求傳回主要端點 IP,且只會在主要端點未通過健康狀態檢查時,傳回備份 IP。Cloud DNS 允許使用者設定「涓流比率」,即使主要目標狀態良好,Cloud DNS 仍可將部分流量傳送至備份目標。比例必須介於 01 之間。預設值為 0

如要測試這項功能,請將網路標記加回 REGION_1 網路伺服器。

新增網路標記

將標記加回 Web Server VM,允許 HTTP 流量傳輸至主要區域 VM。在 Cloud Shell 中執行下列指令。

指令

gcloud compute instances add-tags $REGION_1-instance \
--zone $REGION_1_ZONE --tags allow-http

健康狀態檢查會在 10 秒內通過

確認 DNS 解析指向主要負載平衡器。在我們的設定中,這會是 us-west1 區域中負載平衡器的 IP 位址。

在用戶端執行個體中執行下列指令

指令

dig +short failover.example.com

更新 DNS 記錄

現在,我們要修改 failover.example.com 的 DNS 記錄,即使主要目標健康狀態良好,仍要將 30% 的流量導入備份集。在 Cloud Shell 中執行下列指令

指令

gcloud dns record-sets update failover.example.com --ttl 30 --type A \
--routing-policy-type=FAILOVER \
--routing-policy-primary-data=$REGION_1-ilb \
--routing-policy-backup-data="${REGION_1}=${REGION_2}-ilb;${REGION_2}=${REGION_2}-ilb" \
--routing-policy-backup-data-type=GEO \
--zone=example-com --enable-health-checking \
--backup-data-trickle-ratio=0.3

DNS 解析

從用戶端 VM 執行下列指令。您會發現 DNS 記錄 failover.example.com 大約 70% 的時間會解析為主要負載平衡器 IP,大約 30% 的時間會解析為備用負載平衡器 IP。

for i in {1..10}; do echo $i; dig failover.example.com +short; sleep 6; done

13. 清除步驟

如要清除本實驗室中使用的資源,請從 Cloud Shell 執行下列指令:

gcloud dns record-sets delete failover.example.com --type=A \
--zone=example-com --quiet

gcloud dns managed-zones delete example-com --quiet

gcloud compute forwarding-rules delete $REGION_1-ilb \
--region=$REGION_1 --quiet

gcloud compute forwarding-rules delete $REGION_2-ilb \
--region=$REGION_2 --quiet

gcloud compute backend-services delete $REGION_1-backend-service \
--region=$REGION_1 --quiet

gcloud compute backend-services delete $REGION_2-backend-service \
--region=$REGION_2 --quiet

gcloud compute health-checks delete http-hc --quiet

gcloud compute instances delete client-instance --zone=$REGION_1_ZONE --quiet

gcloud compute instance-groups unmanaged delete $REGION_1-instance-group \
--zone=$REGION_1_ZONE --quiet

gcloud compute instance-groups unmanaged delete $REGION_2-instance-group \
--zone=$REGION_2_ZONE --quiet

gcloud compute instances delete $REGION_1-instance \
--zone=$REGION_1_ZONE --quiet

gcloud compute instances delete $REGION_2-instance \
--zone=$REGION_2_ZONE --quiet

gcloud compute routers nats delete $REGION_1-nat-gw \
--router=$REGION_1-cloudrouter --region=$REGION_1 --quiet

gcloud compute routers nats delete $REGION_2-nat-gw \
--router=$REGION_2-cloudrouter --region=$REGION_2 --quiet

gcloud compute routers delete $REGION_1-cloudrouter \
--region=$REGION_1 --quiet

gcloud compute routers delete $REGION_2-cloudrouter \
--region=$REGION_2 --quiet

gcloud compute firewall-rules delete allow-ssh allow-http-lb-hc --quiet

gcloud compute networks subnets delete $REGION_1-subnet \
--region=$REGION_1 --quiet

gcloud compute networks subnets delete $REGION_2-subnet \
--region=$REGION_2 --quiet

gcloud compute networks delete my-vpc --quiet

14. 恭喜

恭喜,您已成功部署及測試 Cloud DNS 容錯移轉轉送政策

涵蓋內容

  • 如何設定 Cloud DNS 容錯移轉轉送政策
  • 測試 DNS 容錯移轉
  • 如何將流量逐步導入備份集

後續步驟

  • 嘗試為作用中和備份集設定多個 IP
  • 嘗試在非代管執行個體群組中新增多個後端 VM
  • 請嘗試在不同區域設定多個負載平衡器,以備份集中的地理位置政策。

瞭解詳情

https://cloud.google.com/dns/docs/zones/manage-routing-policies