如何為 AlloyDB 建立 Private Service Connect

1. 簡介

在本程式碼實驗室中,您將瞭解如何部署 AlloyDB 的 Private Service Connect,以及如何使用已部署的 Private Service Connect 存取 AlloyDB 服務。

1cd460fc0abeee2c.png

如要進一步瞭解 Private Service Connect,請參閱這篇文章

必要條件

  • Google Cloud 控制台的基本知識
  • 指令列介面和 Google Cloud Shell 的基本技能

課程內容

  • 如何部署 AlloyDB 叢集和執行個體
  • 如何部署 Private Service Connect
  • 如何透過 Private Service Connect 從 VM 連線至 AlloyDB 執行個體

軟硬體需求

  • Google Cloud 帳戶和 Google Cloud 專案
  • 網路瀏覽器,例如 Chrome

2. 設定和需求

自修實驗室環境設定

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

295004821bab6a87.png37d264871000675d.png5e3ff691252acf41.png

  • 專案名稱是這個專案參與者的顯示名稱。這是 Google API 未使用的字元字串。你隨時可以更新該位置資訊。
  • 專案 ID 在所有 Google Cloud 專案中不得重複,且設定後即無法變更。Cloud 控制台會自動產生不重複的字串,通常您不需要在意這個字串。在大多數程式碼研究室中,您需要參照專案 ID (通常會標示為 PROJECT_ID)。如果您不喜歡產生的 ID,可以產生另一個隨機 ID。你也可以嘗試使用自己的名稱,看看是否可用。完成這個步驟後就無法變更,且專案期間都會維持這個設定。
  • 請注意,部分 API 會使用第三個值,也就是「專案編號」。如要進一步瞭解這三種值,請參閱說明文件

注意:專案 ID 在全域中是唯一的,選定後就無法再供他人使用。您是該 ID 的唯一使用者。即使專案已刪除,ID 也無法再次使用

  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. 事前準備

啟用 API

請注意,如果您未使用促銷方案,啟用部分資源會產生費用。正常情況下,實驗室完成後所有資源都會遭到毀損,因此所有資源的費用不會超過 $5 美元。建議您查看帳單,確認這項措施是否可接受。

在 Cloud Shell 中,確認專案 ID 已設定完畢:

通常專案 ID 會顯示在 Cloud Shell 的命令提示字元中,並以半形括號括住,如圖片所示:

edbf16c09a01fbab.png

gcloud config set project [YOUR-PROJECT-ID]

系統會彈出視窗,要求您授權 Cloud Shell。請點選「授權」

33fbeb082b3aac19.png

然後將 PROJECT_ID 環境變數設為 Google Cloud 專案 ID:

PROJECT_ID=$(gcloud config get-value project)

將 REGION 和 ZONE 環境變數設為偏好的地區和可用區:

REGION=europe-west4
ZONE=europe-west4-a

啟用所有必要服務:

gcloud services enable compute.googleapis.com \
                       alloydb.googleapis.com \
                       dns.googleapis.com \
                       servicenetworking.googleapis.com \
                       iam.googleapis.com 

預期輸出內容:

student@cloudshell:~ (psc-alloydb-test)$ gcloud services enable compute.googleapis.com \
                       alloydb.googleapis.com \
                       dns.googleapis.com \
                       servicenetworking.googleapis.com \
                       iam.googleapis.com
Operation "operations/acat.p2-981315804223-09b8112e-2c2c-4a30-9018-c27e6a06c199" finished successfully.

4. 部署 AlloyDB 叢集

在 Cloud Shell 中,您可以使用指令列建立啟用 Private Service Connect 的新 AlloyDB 叢集:

gcloud alloydb clusters create alloydb-cluster-01 \
    --password=changeme \
    --region=$REGION \
    --project=$PROJECT_ID \
    --enable-private-service-connect

預期輸出

student@cloudshell:~ (psc-alloydb-test)$   gcloud alloydb clusters create alloydb-cluster-01 \
    --password=changeme \
    --region=$REGION \
    --project=$PROJECT_ID \
    --enable-private-service-connect
Operation ID: operation-1739367760591-62df21d80fae8-9aa7c3ab-64604bae
Creating cluster...done.

現在建立 AlloyDB 主要執行個體:

gcloud alloydb instances create alloydb-instance-01 \
      --instance-type=PRIMARY \
      --cpu-count=2 \
      --availability-type=ZONAL \
      --region=$REGION \
      --cluster=alloydb-cluster-01 \
      --project=$PROJECT_ID \
      --allowed-psc-projects=$PROJECT_ID

預期輸出

student@cloudshell:~ (psc-alloydb-test)$   gcloud alloydb instances create alloydb-instance-01 \
      --instance-type=PRIMARY \
      --cpu-count=2 \
      --availability-type=ZONAL \
      --region=$REGION \
      --cluster=alloydb-cluster-01 \
      --project=$PROJECT_ID \
      --allowed-psc-projects=$PROJECT_ID
Operation ID: operation-1739368280521-62df23c7e7bda-7e52597c-8c7d9d79
Creating instance...done.

5. 設定 Private Service Connect

以下網路相關工作假設您已建立名為 default 的虛擬私有雲。

預留內部 IP 位址

在環境變數 REGION 參照的 GCP 區域中,找出 VPC 子網路 CIDR 範圍,並在其中選擇 Private Service Connect 端點的可用 IP 位址:

gcloud compute networks subnets describe default \
             --region=$REGION --project=$PROJECT_ID \
             --format="value(ipCidrRange)"

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud compute networks subnets describe default \
             --region=$REGION --project=$PROJECT_ID \
             --format="value(ipCidrRange)"
10.164.0.0/20

在上述取得的 VPC 子網路 CIDR 範圍中,為 Private Service Connect 端點預留內部 IP 位址:

gcloud compute addresses create alloydb-psc \
--project=$PROJECT_ID \
--region=$REGION \
--subnet=default \
--addresses=10.164.0.10

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute addresses create alloydb-psc \
--project=$PROJECT_ID \
--region=$REGION \
--subnet=default \
--addresses=10.164.0.10
Created [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/regions/europe-west4/addresses/alloydb-psc].

確認已預留內部 IP 位址,且狀態為「RESERVED」。

gcloud compute addresses list --project=$PROJECT_ID \
     --filter="name=alloydb-psc"

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute addresses list --project=$PROJECT_ID \
--filter="name=alloydb-psc"
NAME: alloydb-psc
ADDRESS/RANGE: 10.164.0.10
TYPE: INTERNAL
PURPOSE: GCE_ENDPOINT
NETWORK: 
REGION: europe-west4
SUBNET: default
STATUS: RESERVED

取得服務連結 URI

建立啟用 Private Service Connect 的 AlloyDB 執行個體後,請取得服務連結 URI,並使用該 URI 和上述預留的內部 IP 位址,建立 Private Service Connect 端點。

gcloud alloydb instances describe alloydb-instance-01 \
    --cluster=alloydb-cluster-01 \
    --region="$REGION" \
    --format="value(pscInstanceConfig.serviceAttachmentLink)" | \
    sed 's|.*/projects/|projects/|'

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud alloydb instances describe alloydb-instance-01 \
    --cluster=alloydb-cluster-01 \
    --region="$REGION" \
    --format="value(pscInstanceConfig.serviceAttachmentLink)" | \
    sed 's|.*/projects/|projects/|'
projects/se8c7a64d55e2e1f9p-tp/regions/europe-west4/serviceAttachments/alloydb-69f67b56-9fa-alloydb-instance-sa

建立 Private Service Connect

建立 Private Service Connect 端點,並指向 AlloyDB 服務連結 URI:

gcloud compute forwarding-rules create alloydb-psc-ep \
--address=alloydb-psc \
--project=$PROJECT_ID \
--region=$REGION \
--network=default \
--target-service-attachment=projects/se8c7a64d55e2e1f9p-tp/regions/europe-west4/serviceAttachments/alloydb-69f67b56-9fa-alloydb-instance-sa \
--allow-psc-global-access

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute forwarding-rules create alloydb-psc-ep \
--address=alloydb-psc \
--project=$PROJECT_ID \
--region=$REGION \
--network=default \
--target-service-attachment=projects/se8c7a64d55e2e1f9p-tp/regions/europe-west4/serviceAttachments/alloydb-69f67b56-9fa-alloydb-instance-sa \
--allow-psc-global-access
Created [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/regions/europe-west4/forwardingRules/alloydb-psc-ep].

確認端點可連至服務連結:

gcloud compute forwarding-rules describe alloydb-psc-ep \
--project=$PROJECT_ID \
--region=$REGION \
--format="value(pscConnectionStatus)"

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute forwarding-rules describe alloydb-psc-ep \
--project=$PROJECT_ID \
--region=$REGION \
--format="value(pscConnectionStatus)"
ACCEPTED

設定 DNS 代管區域

如要為 AlloyDB 執行個體新增建議的 DNS 名稱,建議您在對應的虛擬私有雲網路中建立私人 DNS 區域:

gcloud dns managed-zones create alloydb-dns \
--project=$PROJECT_ID \
--description="DNS zone for the AlloyDB instances" --dns-name=$REGION.alloydb-psc.goog. \
--networks=default \
--visibility=private

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud dns managed-zones create alloydb-dns \
--project=$PROJECT_ID \
--description="DNS zone for the AlloyDB instances" --dns-name=$REGION.alloydb-psc.goog. \
--networks=default \
--visibility=private
Created [https://dns.googleapis.com/dns/v1/projects/psc-alloydb-test/managedZones/alloydb-dns].

為 Private Service Connect 新增 DNS 記錄

取得 AlloyDB 執行個體的建議 DNS 記錄:

gcloud alloydb instances describe alloydb-instance-01 \
--cluster=alloydb-cluster-01 --region=$REGION --project=$PROJECT_ID \
--format="value(pscInstanceConfig.pscDnsName)"

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud alloydb instances describe alloydb-instance-01 \
--cluster=alloydb-cluster-01 --region=$REGION --project=$PROJECT_ID \
--format="value(pscInstanceConfig.pscDnsName)"
69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog.

將建議的 DNS 記錄新增至 DNS 代管區域。

gcloud dns record-sets create 69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog. \
--project=$PROJECT_ID \
--type=A \
--rrdatas=10.164.0.10 \
--zone=alloydb-dns

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud dns record-sets create 69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog. \
--project=$PROJECT_ID \
--type=A \
--rrdatas=10.164.0.10 \
--zone=alloydb-dns
NAME: 69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog.
TYPE: A
TTL: 0
DATA: 10.164.0.10

6. 準備 Google Compute Engine 虛擬機器

部署 Google Compute Engine 虛擬機器

虛擬機器 (VM) 將用於連線至 AlloyDB 執行個體。

gcloud compute instances create alloydb-client \
    --zone=$ZONE \
--create-disk=auto-delete=yes,boot=yes,image=projects/debian-cloud/global/images/$(gcloud compute images list --filter="family=debian-12 AND family!=debian-12-arm64" --format="value(name)") \
    --scopes=https://www.googleapis.com/auth/cloud-platform \
    --shielded-secure-boot \
    --network-interface=no-address

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute instances create alloydb-client \
    --zone=$ZONE \
--create-disk=auto-delete=yes,boot=yes,image=projects/debian-cloud/global/images/$(gcloud compute images list --filter="family=debian-12 AND family!=debian-12-arm64" --format="value(name)") \
    --scopes=https://www.googleapis.com/auth/cloud-platform \
    --network-interface=no-address
Created [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/zones/europe-west4-a/instances/alloydb-client].
NAME: alloydb-client
ZONE: europe-west4-a
MACHINE_TYPE: n1-standard-1
PREEMPTIBLE: 
INTERNAL_IP: 10.164.0.2
EXTERNAL_IP: 
STATUS: RUNNING

安裝 Postgres 用戶端

建立 Cloud NAT,讓 VM 能夠存取 Linux 存放區的網際網路傳出流量:

gcloud compute routers create cloud-nat-router \
    --network=default \
    --region=$REGION

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute routers create cloud-nat-router \
    --network=default \
    --region=$REGION
Creating router [cloud-nat-router]...done.                                                                                                                                                                                      
NAME: cloud-nat-router
REGION: europe-west4
NETWORK: default
gcloud compute routers nats create cloud-nat \
    --router=cloud-nat-router \
    --region=$REGION  \
    --nat-all-subnet-ip-ranges \
    --auto-allocate-nat-external-ips

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute routers nats create cloud-nat \
    --router=cloud-nat-router \
    --region=$REGION  \
    --nat-all-subnet-ip-ranges \
    --auto-allocate-nat-external-ips
Creating NAT [cloud-nat] in router [cloud-nat-router]...done.

在已部署的 VM 上安裝 PostgreSQL 用戶端軟體

連線至 VM:

gcloud compute ssh --zone $ZONE "alloydb-client" --tunnel-through-iap --project $PROJECT_ID

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute ssh --zone $ZONE "alloydb-client" --tunnel-through-iap --project $PROJECT_ID
WARNING: 

To increase the performance of the tunnel, consider installing NumPy. For instructions,
please see https://cloud.google.com/iap/docs/using-tcp-forwarding#increasing_the_tcp_upload_bandwidth

Warning: Permanently added 'compute.3358765012415130370' (ED25519) to the list of known hosts.
Linux alloydb-client 6.1.0-29-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.123-1 (2025-01-02) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Creating directory '/home/student_tampferl_altostrat_com'.

在 VM 內執行下列指令,安裝軟體:

sudo apt-get update
sudo apt-get install --yes postgresql-client

預期輸出

sudo apt-get update
sudo apt-get install --yes postgresql-client
Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B]
Get:5 file:/etc/apt/mirrors/debian-security.list Mirrorlist [39 B]
Get:7 https://packages.cloud.google.com/apt google-compute-engine-bookworm-stable InRelease [1321 B]
Get:2 https://deb.debian.org/debian bookworm InRelease [151 kB]              
Get:3 https://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]     
Get:4 https://deb.debian.org/debian bookworm-backports InRelease [59.0 kB]
...redacted...
update-alternatives: using /usr/share/postgresql/15/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-client (15+248) ...
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u9) ...

7. 透過 Private Service Connect 連線至 AlloyDB for PostgreSQL 執行個體

連線至執行個體

psql "dbname=postgres user=postgres host=69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog."

預期輸出

student_tampferl_altostrat_com@alloydb-client:~$ psql "dbname=postgres user=postgres host=69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog."
Password for user postgres: 
psql (15.10 (Debian 15.10-0+deb12u1), server 15.7)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

postgres=> 

建立及測試資料庫

建立資料庫

CREATE DATABASE company;

預期輸出

postgres=> CREATE DATABASE company;
CREATE DATABASE
postgres=> 

列出所有資料庫

\l

預期輸出

     Name       |      Owner       | Encoding | Collate | Ctype | ICU Locale | Locale Provider |           Access privileges           
-----------------+------------------+----------+---------+-------+------------+-----------------+---------------------------------------
 alloydbadmin    | alloydbadmin     | UTF8     | C       | C     | und-x-icu  | icu             | 
 alloydbmetadata | alloydbadmin     | UTF8     | C       | C     | und-x-icu  | icu             | alloydbadmin=CTc/alloydbadmin        +
                 |                  |          |         |       |            |                 | alloydbmetadata=c/alloydbadmin
 company         | postgres         | UTF8     | C       | C     | und-x-icu  | icu             | 
 postgres        | alloydbsuperuser | UTF8     | C       | C     | und-x-icu  | icu             | 
 template0       | alloydbadmin     | UTF8     | C       | C     | und-x-icu  | icu             | =c/alloydbadmin                      +
                 |                  |          |         |       |            |                 | alloydbadmin=CTc/alloydbadmin
 template1       | alloydbsuperuser | UTF8     | C       | C     | und-x-icu  | icu             | =c/alloydbsuperuser                  +
                 |                  |          |         |       |            |                 | alloydbsuperuser=CTc/alloydbsuperuser
(6 rows)

連至員工資料庫

\c company

預期輸出

postgres=> \c company
psql (15.10 (Debian 15.10-0+deb12u1), server 15.7)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
You are now connected to database "company" as user "postgres".
company=>

在公司資料庫中建立資料表

CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    first VARCHAR(255) NOT NULL,
    last VARCHAR(255) NOT NULL,
    salary DECIMAL (10, 2)
);

預期輸出

company=> CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    first VARCHAR(255) NOT NULL,
    last VARCHAR(255) NOT NULL,
    salary DECIMAL (10, 2)
);
CREATE TABLE

將資料插入公司資料庫的員工資料表

INSERT INTO employees (first, last, salary) VALUES
    ('Max', 'Mustermann', 5000.00),
    ('Anna', 'Schmidt', 7000.00),
    ('Peter', 'Mayer', 6000.00);

預期輸出

company=> INSERT INTO employees (first, last, salary) VALUES
    ('Max', 'Mustermann', 5000.00),
    ('Anna', 'Schmidt', 7000.00),
    ('Peter', 'Mayer', 6000.00);
INSERT 0 3
company=>

查詢員工資料表

SELECT * FROM employees;

預期輸出

company=> SELECT * FROM employees;
 id | first |    last    | salary  
----+-------+------------+---------
  1 | Max   | Mustermann | 5000.00
  2 | Anna  | Schmidt    | 7000.00
  3 | Peter | Mayer      | 6000.00
(3 rows)
company=> 

退出 Postgres 資料庫和 VM,然後返回 Cloud Shell:

\q
exit

預期輸出

company=> \q
student_tampferl_altostrat_com@alloydb-client:~$ exit
logout
Connection to compute.3358765012415130370 closed.
student@cloudshell:~ (psc-alloydb-test)$ 

8. 清除環境

完成實驗室後,請刪除專案中的所有 Google Cloud 資源。

刪除 AlloyDB 叢集

在 Cloud Shell 中刪除 AlloyDB for Postgres 叢集:

gcloud alloydb clusters delete alloydb-cluster-01 --region=$REGION --force --quiet

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud alloydb clusters delete alloydb-cluster-01 --region=$REGION --force --quiet
Operation ID: operation-1739488287386-62e0e2d75ead0-f8ffd91f-9c0f56c1
Deleting cluster...done.

刪除 Google Compute Engine 虛擬機器

在 Cloud Shell 中刪除 VM:

gcloud compute instances delete alloydb-client \
    --zone=$ZONE \
    --quiet

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute instances delete alloydb-client \
    --zone=$ZONE \
    --quiet
Deleted [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/zones/europe-west4-a/instances/alloydb-client].

刪除網路元件

刪除網路相關元件:Cloud NAT、Cloud Router、Private Service Connect 端點、保留的內部 IP 位址、DNS 記錄和 DNS 代管可用區。

刪除 Cloud NAT:

gcloud compute routers nats delete cloud-nat \
    --router=cloud-nat-router \
    --region=$REGION \
    --quiet

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute routers nats delete cloud-nat \
    --router=cloud-nat-router \
    --region=$REGION \
    --quiet
Updated [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/regions/europe-west4/routers/cloud-nat-router].

刪除 Cloud Router:

gcloud compute routers delete cloud-nat-router \
    --region=$REGION \
    --quiet 

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute routers delete cloud-nat-router \
    --region=$REGION \
    --quiet
Deleted [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/regions/europe-west4/routers/cloud-nat-router].

刪除 Private Service Connect 端點:

gcloud compute forwarding-rules delete alloydb-psc-ep \
    --project=$PROJECT_ID \
    --region=$REGION \
    --quiet

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute forwarding-rules delete alloydb-psc-ep \
    --project=$PROJECT_ID \
    --region=$REGION \
    --quiet
Deleted [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/regions/europe-west4/forwardingRules/alloydb-psc-ep].

釋出預留的內部 IP 位址:

gcloud compute addresses delete alloydb-psc \
   --project=$PROJECT_ID \
   --region=$REGION \
   --quiet

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud compute addresses delete alloydb-psc \
   --project=$PROJECT_ID \
   --region=$REGION \
   --quiet
Deleted [https://www.googleapis.com/compute/v1/projects/psc-alloydb-test/regions/europe-west4/addresses/alloydb-psc].

刪除 DNS 記錄:

gcloud dns record-sets delete 69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog. \
--project=$PROJECT_ID \
--type=A \
--zone=alloydb-dns

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud dns record-sets delete 69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog. \
--project=$PROJECT_ID \
--type=A \
--zone=alloydb-dns
Deleted [https://dns.googleapis.com/dns/v1/projects/psc-alloydb-test/managedZones/alloydb-dns/rrsets/69f67b56-9fa2-4480-89f6-3f1a38ee51cb.6a495301-4802-4ec1-bb9b-69b57d2616ec.europe-west4.alloydb-psc.goog./A].

刪除 DNS 代管區域:

gcloud dns managed-zones delete alloydb-dns \
   --project=$PROJECT_ID \
   --quiet

預期輸出

student@cloudshell:~ (psc-alloydb-test)$ gcloud dns managed-zones delete alloydb-dns \
   --project=$PROJECT_ID \
   --quiet
Deleted [https://dns.googleapis.com/dns/v1/projects/psc-alloydb-test/managedZones/alloydb-dns].

9. 恭喜

恭喜您完成本程式碼研究室。

涵蓋內容

  • 如何部署 AlloyDB 叢集和執行個體
  • 如何部署 Private Service Connect
  • 如何透過 Private Service Connect 從 VM 連線至 AlloyDB 執行個體

10. 問卷調查

您會如何使用本教學課程?

僅閱讀內容 閱讀內容並完成練習