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

1. מבוא

ב-codelab הזה תלמדו איך לפרוס חיבור Private Service Connect ל-Cloud SQL ואיך לגשת לשירות Cloud SQL באמצעות 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.png37d264871000675d.png5e3ff691252acf41.png

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

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

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

הפעלת Cloud Shell

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

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

55efc1aaa7a4d3ad.png

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

7ffe5cbb04455448.png

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

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

הפעלת ה-API

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

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

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

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 הפנימית שמורה ושמוצג הסטטוס 'שמורה' בכתובת ה-IP.

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

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

מוודאים שאפשר להתחבר לנקודת הקצה באמצעות הצירוף לשירות:

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 עבור מכונה של 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:

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 Endpoint, ‏ כתובת 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. סקר

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

רק לקרוא לקרוא ולהשלים את התרגילים