如何為 AlloyDB 建立 Private Service Connect

1. 簡介

在本程式碼研究室中,您將瞭解如何為 AlloyDB 部署 Private Service Connection,以及如何使用已部署的 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

  • 「Project name」是這個專案參與者的顯示名稱。這是 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

這個虛擬機器會載入您需要的所有開發工具。提供永久的 5 GB 主目錄,而且在 Google Cloud 中運作,可大幅提升網路效能和驗證功能。您可以在瀏覽器中完成本程式碼研究室的所有工作。您不需要安裝任何東西。

3. 事前準備

啟用 API

請注意,如果您未使用促銷方案,啟用的部分資源將產生費用。在一般情況下,如果所有資源在研究室結束後都會遭到銷毀,所有資源的費用不會超過 $5 美元。建議你查看帳單,確認這項運動是否符合你的需求。

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

通常,Cloud Shell 的命令提示會在括號內顯示專案 ID,如下圖所示:

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 中,您可以使用指令列建立新的 AlloyDB 叢集,並啟用 Private Service Connect:

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 的 VPC。

保留內部 IP 位址

在環境變數 REGION 中找到 GCP 地區的 VPC 子網路 CIDR 範圍,然後在這個 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

在上述衍生虛擬私有雲子網路 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 位址已保留,且 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 建立 Private Service Connect 端點,並使用上述保留的內部 IP 位址。

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 名稱,建議您在對應的 VPC 網路中建立不公開 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 Postgres 執行個體

連線至執行個體

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

將資料插入公司資料庫的 employees 資料表

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=>

查詢「employees」資料表

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. 問卷調查

您要如何使用這個教學課程?

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