איך יוצרים Private Service Connect ל-CloudSQL

1. מבוא

ב-Codelab הזה נסביר איך פורסים Private Service Connect ל-CloudSQL ואיך ניגשים לשירות CloudSQL באמצעות Private Service Connect שנפרס. .

8e3d735974c36aa9.png

כאן אפשר לקבל מידע נוסף על Private Service Connect.

דרישות מוקדמות

  • הבנה בסיסית של מסוף Google Cloud
  • מיומנויות בסיסיות בממשק שורת הפקודה וב-Google Cloud Shell

מה תלמדו

  • איך פורסים מופע של Cloud SQL
  • איך פורסים Private Service Connect
  • איך מתחברים ממכונה וירטואלית למופע Cloud SQL באמצעות Private Service Connect

מה תצטרכו

  • חשבון Google Cloud ופרויקט Google Cloud
  • דפדפן אינטרנט כמו Chrome

2. הגדרה ודרישות

הגדרת סביבה בקצב אישי

  1. נכנסים ל-מסוף Google Cloud ויוצרים פרויקט חדש או משתמשים בפרויקט קיים. אם עדיין אין לכם חשבון Gmail או Google Workspace, אתם צריכים ליצור חשבון.

295004821bab6a87.png 37d264871000675d.png 5e3ff691252acf41.png

  • שם הפרויקט הוא השם המוצג למשתתפים בפרויקט. זו מחרוזת תווים שלא נמצאת בשימוש ב-Google APIs. אפשר לעדכן את המיקום הזה בכל שלב.
  • מזהה הפרויקט חייב להיות ייחודי לכל הפרויקטים ב-Google Cloud, והוא קבוע (אי אפשר לשנות אותו אחרי שהוא מוגדר). מסוף Cloud יוצר באופן אוטומטי מחרוזת ייחודית, ובדרך כלל לא צריך לדעת מה היא. ברוב ה-Codelabs, תצטרכו להפנות למזהה הפרויקט (בדרך כלל הוא מזוהה כ-PROJECT_ID). אם אתם לא אוהבים את המזהה שנוצר, אתם יכולים ליצור מזהה אקראי אחר. אפשר גם לנסות שם משתמש משלכם ולבדוק אם הוא זמין. אי אפשר לשנות את ההגדרה הזו אחרי השלב הזה, והיא תישאר כזו למשך הפרויקט.
  • לידיעתכם, יש ערך שלישי, מספר פרויקט, שחלק מממשקי ה-API משתמשים בו. מידע נוסף על שלושת הערכים האלה מופיע במאמרי העזרה.

שימו לב: מזהה הפרויקט הוא ייחודי גלובלית, ואחרי שתבחרו אותו אף אחד אחר לא יוכל להשתמש בו. אתם המשתמשים היחידים במזהה הזה. גם אם פרויקט נמחק, אי אפשר להשתמש שוב במזהה שלו.

  1. בשלב הבא, תצטרכו להפעיל את החיוב במסוף Cloud כדי להשתמש במשאבי Cloud או בממשקי API של Cloud. השלמת ה-codelab הזה לא תעלה לכם הרבה, אם בכלל. כדי להשבית את המשאבים ולמנוע חיובים נוספים אחרי שתסיימו את המדריך הזה, תוכלו למחוק את המשאבים שיצרתם או למחוק את הפרויקט. משתמשים חדשים ב-Google Cloud זכאים לתוכנית תקופת ניסיון בחינם בשווי 300$.

מפעילים את Cloud Shell

אפשר להפעיל את Google Cloud מרחוק מהמחשב הנייד, אבל ב-Codelab הזה נשתמש ב-Google Cloud Shell, סביבת שורת פקודה שפועלת בענן.

ב-מסוף Google Cloud, לוחצים על סמל Cloud Shell בסרגל הכלים שבפינה הימנית העליונה:

55efc1aaa7a4d3ad.png

הקצאת המשאבים והחיבור לסביבה יימשכו רק כמה רגעים. בסיום התהליך, אמור להופיע משהו כזה:

7ffe5cbb04455448.png

המכונה הווירטואלית הזו כוללת את כל הכלים שדרושים למפתחים. יש בה ספריית בית בנפח מתמיד של 5GB והיא פועלת ב-Google Cloud, מה שמשפר מאוד את הביצועים והאימות ברשת. אפשר לבצע את כל העבודה ב-codelab הזה בדפדפן. לא צריך להתקין שום דבר.

3. לפני שמתחילים

הפעלת ה-API

חשוב לדעת שאם לא משתמשים ברמה של שובר הפרסום, חלק מהמשאבים שמפעילים יגררו עלויות. בנסיבות רגילות, אם כל המשאבים נמחקים בסיום שיעור ה-Lab, העלות של כל המשאבים לא תעלה על 5$. מומלץ לבדוק את החיובים ולוודא שהפעולה הזו מקובלת עליכם.

ב-Cloud Shell, מוודאים שמזהה הפרויקט מוגדר:

בדרך כלל מזהה הפרויקט מוצג בסוגריים בשורת הפקודה ב-Cloud Shell, כמו שמוצג בתמונה:

edbf16c09a01fbab.png

gcloud config set project [YOUR-PROJECT-ID]

ייפתח חלון קופץ שבו תתבקשו לאשר את Cloud Shell. עליך ללחוץ על הרשאה

33fbeb082b3aac19.png

אחר כך מגדירים את משתנה הסביבה PROJECT_ID למזהה הפרויקט ב-Google Cloud:

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. פריסת מכונה של Cloud SQL ל-Postgres

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

שינוי הסיסמה של משתמש מסד הנתונים 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

במשימות הבאות שקשורות לרשת, ההנחה היא שקיימת רשת VPC בשם default.

שמירת כתובת IP פנימית

מוצאים את טווח ה-CIDR של תת-הרשת של ה-VPC באזור GCP שאליו מתייחס משתנה הסביבה REGION, ובוחרים כתובת IP פנויה בטווח ה-CIDR הזה עבור נקודת הקצה של Private Service Connect:

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

שומרים כתובת IP פנימית לנקודת הקצה של Private Service Connect בטווח CIDR של תת-רשת ה-VPC שנגזר למעלה:

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 מופיע עבור כתובת ה-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 של קובץ השירות המצורף

אחרי שיוצרים מופע Cloud SQL עם Private Service Connect מופעל, מקבלים את מזהה ה-URI של הקובץ המצורף לשירות ומשתמשים בו כדי ליצור את נקודת הקצה (endpoint) של 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 ומפנים אותה למזהה ה-URI של הקובץ המצורף לשירות Cloud SQL:

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].

מוודאים שנקודת הקצה יכולה להתחבר ל-Service Attachment:

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

כדי להוסיף את שם ה-DNS המוצע למופע Cloud SQL, מומלץ ליצור אזור DNS פרטי ברשת ה-VPC המתאימה:

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].

הוספת רשומת DNS ל-Private Service Connect

מקבלים את רשומת ה-DNS המוצעת למכונה של Cloud SQL:

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 Client

יוצרים Cloud NAT לתעבורה יוצאת לאינטרנט שהמכונה הווירטואלית יכולה לגשת למאגרי 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.

התקנת תוכנת הלקוח של 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. התחברות למכונה של Cloud SQL for Postgres באמצעות Private Service Connect

התחברות למופע

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

שאילתה של טבלת העובדים

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 ומהמכונה הווירטואלית וחוזרים אל Cloud Shell:

\q
exit

הפלט הצפוי

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

8. ניקוי הסביבה

בסיום שיעור ה-Lab, צריך להרוס את כל המשאבים ב-Google Cloud בפרויקט.

מחיקת מופע Cloud SQL Postgres

ב-Cloud Shell, מוחקים את המופע של Cloud SQL ל-Postgres:

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, נקודת קצה (endpoint) של 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. מזל טוב

כל הכבוד, סיימתם את ה-Codelab.

מה נכלל

  • איך פורסים מופע של Cloud SQL
  • איך פורסים Private Service Connect
  • איך מתחברים ממכונה וירטואלית למופע Cloud SQL באמצעות Private Service Connect

10. סקר

איך תשתמשו במדריך הזה?

רק קוראים את הטקסט קוראים את הטקסט ומבצעים את התרגילים