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

1. מבוא

בקודלאב הזה תלמדו איך לפרוס חיבור של Private Service Connect ל-AlloyDB ואיך לגשת לשירות AlloyDB באמצעות Private Service Connect שנפרס.

1cd460fc0abeee2c.png

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

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

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

מה תלמדו

  • איך לפרוס אשכול ומכונה של AlloyDB
  • איך לפרוס Private Service Connect
  • איך מתחברים ממכונה וירטואלית למכונה של AlloyDB דרך 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 \
                       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

במשימות הבאות שקשורות לרשת, ההנחה היא שקיימת רשת 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 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.

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

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

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

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

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

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

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

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 Client

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

התקנת תוכנת הלקוח של 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. התחברות למכונה של AlloyDB ל-Postgres דרך Private Service Connect

התחברות למכונה

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

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

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

הפלט הצפוי

company=> \q
student_tampferl_altostrat_com@alloydb-client:~$ exit
logout
Connection to compute.3358765012415130370 closed.
student@cloudshell:~ (psc-alloydb-test)$ 

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

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

מחיקת אשכול AlloyDB

ב-Cloud Shell, מוחקים את האשכול של AlloyDB ל-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:

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 Endpoint, ‏ כתובת 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. מזל טוב

כל הכבוד על השלמת ה-Codelab.

מה עסקנו בו

  • איך לפרוס מכונת AlloyDB ואשכול AlloyDB
  • איך לפרוס Private Service Connect
  • איך מתחברים ממכונה וירטואלית למכונה של AlloyDB דרך Private Service Connect

10. סקר

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

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