如何為 CloudSQL 建立 Private Service Connect

1. 簡介

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

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

  • 「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 \
                       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. 部署 Postgres 適用的 Cloud SQL 執行個體

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

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

成功安裝 PostgreSQL 適用的 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 的 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 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 位址已保留,且 IP 位址的狀態為「保留」。

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

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud compute addresses list cloudsql-psc \
--project=$PROJECT_ID
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 建立 Private Service Connect 端點,並使用上述保留的內部 IP 位址。

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

預期輸出

student@cloudshell:~ (psc-cloud-sql-test)$ gcloud sql instances describe cloudsql-postgres1 --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 連線至 Cloud SQL for Postgres 執行個體

連線至執行個體

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

將資料插入公司資料庫的 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

預期輸出

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 中刪除 Postgres 適用的 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. 問卷調查

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

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