如何為 Cloud SQL 建立 Private Service Connect

1. 簡介

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

8e3d735974c36aa9.png

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

必要條件

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

課程內容

  • 如何部署 Cloud SQL 執行個體
  • 如何部署 Private Service Connect
  • 如何透過 Private Service Connect 從 VM 連線至 Cloud SQL 執行個體

軟硬體需求

  • 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 \
                       sqladmin.googleapis.com \
                       dns.googleapis.com \
                       iam.googleapis.com 

預期輸出內容:

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud services enable compute.googleapis.com \
                       sqladmin.googleapis.com \
                       dns.googleapis.com \
                       iam.googleapis.com
Operation "operations/acat.p2-577410439131-dfb33f74-3447-485c-bae2-bc130126c965" finished successfully.

4. 部署 PostgreSQL 適用的 Cloud SQL 執行個體

在 Cloud Shell 中,您可以使用指令列建立已啟用 Private Service Connect 的新 Cloud SQL Postgres 執行個體:

gcloud sql instances create cloudsql-postgres \
--project=$PROJECT_ID \
--region=$REGION \
--enable-private-service-connect \
--allowed-psc-projects=$PROJECT_ID \
--availability-type=ZONAL \
--no-assign-ip \
--cpu=2 \
--memory=7680MB \
--edition=ENTERPRISE \
--database-version=POSTGRES_16

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud sql instances create cloudsql-postgres \
--project=$PROJECT_ID \
--region=europe-west4 \
--enable-private-service-connect \
--allowed-psc-projects=$PROJECT_ID \
--availability-type=ZONAL \
--no-assign-ip \
--cpu=2 \
--memory=7680MB \
--edition=ENTERPRISE \
--database-version=POSTGRES_16
Creating Cloud SQL instance for POSTGRES_16...done.                                                                                                                                                                             
Created [https://sqladmin.googleapis.com/sql/v1beta4/projects/psc-cloud-sql-test02/instances/cloudsql-postgres1].
NAME: cloudsql-postgres
DATABASE_VERSION: POSTGRES_16
LOCATION: europe-west4-b
TIER: db-custom-2-7680
PRIMARY_ADDRESS: -
PRIVATE_ADDRESS: -
STATUS: RUNNABLE

成功安裝 Postgres 適用的 Cloud SQL 後,請變更資料庫使用者 postgres 的密碼:

gcloud sql users set-password postgres \
  --instance=cloudsql-postgres \
  --password='changeme'

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud sql users set-password postgres \
  --instance=cloudsql-postgres \
  --password='changeme'
Updating Cloud SQL user...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 cloudsql-psc \
--project=$PROJECT_ID \
--region=$REGION \
--subnet=default \
--addresses=10.164.0.10

預期輸出

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

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

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

預期輸出

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

取得服務連結 URI

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

gcloud sql instances describe cloudsql-postgres \
--project=$PROJECT_ID   --format="value(pscServiceAttachmentLink)"

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud sql instances describe cloudsql-postgres --project=$PROJECT_ID \
  --format="value(pscServiceAttachmentLink)"
projects/l639336e2c716e3d8p-tp/regions/europe-west4/serviceAttachments/a-33446dfaf850-psc-service-attachment-e6471fc6708a6cfe

建立 Private Service Connect

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

gcloud compute forwarding-rules create cloudsql-psc-ep \
--address=cloudsql-psc \
--project=$PROJECT_ID \
--region=$REGION \
--network=default \
--target-service-attachment=projects/l639336e2c716e3d8p-tp/regions/europe-west4/serviceAttachments/a-33446dfaf850-psc-service-attachment-e6471fc6708a6cfe \
--allow-psc-global-access

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud compute forwarding-rules create cloudsql-psc-ep \
--address=cloudsql-psc \
--project=$PROJECT_ID \
--region=$REGION \
--network=default \
--target-service-attachment=projects/l639336e2c716e3d8p-tp/regions/europe-west4/serviceAttachments/a-33446dfaf850-psc-service-attachment-e6471fc6708a6cfe \
--allow-psc-global-access
Created [https://www.googleapis.com/compute/v1/projects/psc-cloud-sql-test02/regions/europe-west4/forwardingRules/cloudsql-psc-ep].

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

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

預期輸出

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

設定 DNS 代管區域

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

gcloud dns managed-zones create cloudsql-dns \
--project=$PROJECT_ID \
--description="DNS zone for the Cloud SQL instances" \
--dns-name=$REGION.sql.goog. \
--networks=default \
--visibility=private

預期輸出

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

為 Private Service Connect 新增 DNS 記錄

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

gcloud sql instances describe cloudsql-postgres \
--project=$PROJECT_ID \
--format="value(dnsName)"

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud sql instances describe  cloudsql-postgres --project=$PROJECT_ID --format="value(dnsName)"
33446dfaf850.1rrhex0himzzc.europe-west4.sql.goog.

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

gcloud dns record-sets create 3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog. \
--project=$PROJECT_ID \
--type=A \
--rrdatas=10.164.0.10 \
--zone=cloudsql-dns

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud dns record-sets create 3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog. \
--project=$PROJECT_ID \
--type=A \
--rrdatas=10.164.0.10 \
--zone=cloudsql-dns
NAME: 3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog.
TYPE: A
TTL: 0
DATA: 10.164.0.10

6. 準備 Google Compute Engine 虛擬機器

部署 Google Compute Engine 虛擬機器

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

gcloud compute instances create cloudsql-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

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud compute instances create cloudsql-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-cloud-sql-test02/zones/europe-west4-a/instances/cloudsql-client].
NAME: cloudsql-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-cloud-sql-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-cloud-sql-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 "cloudsql-client" \
--tunnel-through-iap --project $PROJECT_ID

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud compute ssh --zone "europe-west4-a" "cloudsql-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.1355719684363734964' (ED25519) to the list of known hosts.
Linux cloudsql-client 6.1.0-26-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.112-1 (2024-09-30) 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_org_altostrat_com'.

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

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

預期輸出

student@cloudsql-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+deb12u8) ...

7. 透過 Private Service Connect 連線至 PostgreSQL 適用的 Cloud SQL 執行個體

連線至執行個體

psql "sslmode=disable dbname=postgres user=postgres host=3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog."

預期輸出

student@cloudsql-client:~$ psql "sslmode=disable dbname=postgres user=postgres host=3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog."
Password for user postgres: 
psql (15.8 (Debian 15.8-0+deb12u1), server 16.4)
WARNING: psql major version 15, server major version 16.
         Some psql features might not work.
Type "help" for help.

postgres=> 

建立及測試資料庫

建立資料庫

CREATE DATABASE company;

預期輸出

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

列出所有資料庫

\l

預期輸出

postgres=> \l
                                                                List of databases
     Name      |       Owner       | Encoding |  Collate   |   Ctype    | ICU Locale | Locale Provider |            Access privileges            
---------------+-------------------+----------+------------+------------+------------+-----------------+-----------------------------------------
 cloudsqladmin | cloudsqladmin     | UTF8     | en_US.UTF8 | en_US.UTF8 |            | libc            | 
 company     | postgres          | UTF8     | en_US.UTF8 | en_US.UTF8 |            | libc            | 
 postgres      | cloudsqlsuperuser | UTF8     | en_US.UTF8 | en_US.UTF8 |            | libc            | 
 template0     | cloudsqladmin     | UTF8     | en_US.UTF8 | en_US.UTF8 |            | libc            | =c/cloudsqladmin                       +
               |                   |          |            |            |            |                 | cloudsqladmin=CTc/cloudsqladmin
 template1     | cloudsqlsuperuser | UTF8     | en_US.UTF8 | en_US.UTF8 |            | libc            | =c/cloudsqlsuperuser                   +
               |                   |          |            |            |            |                 | cloudsqlsuperuser=CTc/cloudsqlsuperuser
(5 rows)

postgres=>

連至員工資料庫

\c company

預期輸出

postgres=> \c company
psql (15.8 (Debian 15.8-0+deb12u1), server 16.4)
WARNING: psql major version 15, server major version 16.
         Some psql features might not work.
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

預期輸出

postgres=> \q
student@cloudsql-client:~$ exit
logout
Connection to compute.1355719684363734964 closed.
student@cloudshell:~ (psc-cloud-sql-test02)$ 

8. 清除環境

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

刪除 Cloud SQL Postgres 執行個體

在 Cloud Shell 中刪除 PostgreSQL 適用的 Cloud SQL 執行個體:

gcloud sql instances delete cloudsql-postgres --quiet

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud sql instances delete cloudsql-postgres --quiet
Deleting Cloud SQL instance...done.                                                                                                                                                       
Deleted [https://sqladmin.googleapis.com/sql/v1beta4/projects/psc-cloud-sql-test02/instances/cloudsql-postgres].

刪除 Google Compute Engine 虛擬機器

在 Cloud Shell 中刪除 VM:

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

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud compute instances delete cloudsql-client \
    --quiet$ZONE \
    --quiet
Deleted [https://www.googleapis.com/compute/v1/projects/psc-cloud-sql-test02/zones/europe-west4-a/instances/cloudsql-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-cloud-sql-test)$ gcloud compute routers nats delete cloud-nat \
    --router=cloud-nat-router \
    --region=$REGION \
    --quiet
Updated [https://www.googleapis.com/compute/v1/projects/psc-cloud-sql-test02/regions/europe-west4/routers/cloud-nat-router].

刪除 Cloud Router:

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

預期輸出

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

刪除 Private Service Connect 端點:

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

預期輸出

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

釋出預留的內部 IP 位址:

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

預期輸出

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

刪除 DNS 記錄:

gcloud dns record-sets delete 3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog. \
--project=$PROJECT_ID \
--type=A \
--zone=cloudsql-dns

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud dns record-sets delete 3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog. \
--project=$PROJECT_ID \
--type=A \
--zone=cloudsql-dns
Deleted [https://dns.googleapis.com/dns/v1/projects/psc-cloud-sql-test02/managedZones/cloudsql-dns/rrsets/3446dfaf850.1rrhex0himzzc.europe-west4.sql.goog./A].

刪除 DNS 代管區域:

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

預期輸出

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

9. 恭喜

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

涵蓋內容

  • 如何部署 Cloud SQL 執行個體
  • 如何部署 Private Service Connect
  • 如何透過 Private Service Connect 從 VM 連線至 Cloud SQL 執行個體

10. 問卷調查

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

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