使用 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 未使用的字元字串。您可以隨時更新。
  • 所有 Google Cloud 專案的專案 ID 均不得重複,且設定後即無法變更。Cloud 控制台會自動產生一個不重複的字串。但通常是在乎它何在在大部分的程式碼研究室中,您必須參照專案 ID (通常為 PROJECT_ID)。如果您對產生的 ID 不滿意,可以隨機產生一個 ID。此外,您也可以自行嘗試,看看系統是否提供該付款方式。在完成這個步驟後就無法變更,而且在專案期間仍會保持有效。
  • 資訊中的第三個值是專案編號,部分 API 會使用這個編號。如要進一步瞭解這三個值,請參閱說明文件
  1. 接下來,您需要在 Cloud 控制台中啟用計費功能,才能使用 Cloud 資源/API。執行這個程式碼研究室並不會產生任何費用,如果有的話。如要關閉資源,以免系統產生本教學課程結束後產生的費用,您可以刪除自己建立的資源,或刪除整個專案。Google Cloud 的新使用者符合 $300 美元免費試用計畫的資格。

啟動 Cloud Shell

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

Google Cloud 控制台,按一下右上方的工具列上的 Cloud Shell 圖示:

55efc1aaa7a4d3ad.png

佈建並連線至環境的作業只需幾分鐘的時間。完成後,您應該會看到類似下方的內容:

7ffe5cbb04455448.png

這部虛擬機器都裝載了您需要的所有開發工具。提供永久的 5 GB 主目錄,而且在 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 指令建立虛擬私有雲網路。我們將子網路模式設為自訂,因為我們會在下一個步驟中建立自己的子網路。在 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

建立防火牆規則

您必須允許通訊埠 80 來自虛擬私有雲子網路,以及負載平衡器健康狀態檢查 IP 範圍的流量。

此外,您也必須建立防火牆規則來允許用戶端 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 閘道都與單一虛擬私有雲網路、區域和 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 網路伺服器

在 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 網路伺服器

在 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_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 記錄的 TTL 設為 5 秒,因此已新增 6 秒的睡眠計時器。睡眠計時器可確保你在每次收到 DNS 要求時,都能收到未快取的 DNS 回應。這個指令大約需要一分鐘才能執行完成。

您會在輸出結果中看到資源記錄主要集的負載平衡器 IP 位址。設定中的負載平衡器 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 可讓使用者設定 Trickle Ratio,這樣一來,即使主要目標健康狀態良好,Cloud DNS 也能將部分流量傳送至備用目標。負數必須是介於 01 之間的值。預設值為 0

為進行測試,請將網路標記加回 REGION_1 網路伺服器。

新增網路標記

將標記加回網路伺服器 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 會解析為主要負載平衡器的 IP 約定值。70% 的時間和備份負載平衡器 IP 的約定時間。佔 30% 的時間

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

13. 清除步驟

如要清除本研究室中使用的資源,請透過 CloudShell 執行下列指令

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