1. परिचय
इस कोडलैब में, आपको Cloud SQL के लिए Private Service Connect को डिप्लॉय करने का तरीका और डिप्लॉय किए गए Private Service Connect का इस्तेमाल करके, Cloud SQL सेवा को ऐक्सेस करने का तरीका पता चलेगा. .
Private Service Connect के बारे में ज़्यादा जानकारी के लिए, यहां जाएं.
ज़रूरी शर्तें
- Google Cloud Console के बारे में बुनियादी जानकारी
- कमांड-लाइन इंटरफ़ेस और Google Cloud Shell की बुनियादी स्किल
आपको क्या सीखने को मिलेगा
- Cloud SQL इंस्टेंस को डिप्लॉय करने का तरीका
- Private Service Connect को डिप्लॉय करने का तरीका
- प्राइवेट सेवा कनेक्ट की मदद से, किसी वर्चुअल मशीन (VM) से Cloud SQL इंस्टेंस से कनेक्ट करने का तरीका
आपको इन चीज़ों की ज़रूरत होगी
- Google Cloud खाता और Google Cloud प्रोजेक्ट
- Chrome जैसा कोई वेब ब्राउज़र
2. सेटअप और ज़रूरी शर्तें
अपने हिसाब से एनवायरमेंट सेट अप करना
- Google Cloud Console में साइन इन करें और नया प्रोजेक्ट बनाएं या किसी मौजूदा प्रोजेक्ट का फिर से इस्तेमाल करें. अगर आपके पास पहले से कोई Gmail या Google Workspace खाता नहीं है, तो आपको एक खाता बनाना होगा.
- प्रोजेक्ट का नाम, इस प्रोजेक्ट में हिस्सा लेने वाले लोगों के लिए डिसप्ले नेम होता है. यह एक वर्ण स्ट्रिंग है, जिसका इस्तेमाल Google API नहीं करते. इसे कभी भी अपडेट किया जा सकता है.
- प्रोजेक्ट आईडी, Google Cloud के सभी प्रोजेक्ट में यूनीक होना चाहिए. साथ ही, इसे सेट करने के बाद बदला नहीं जा सकता. Cloud Console, अपने-आप एक यूनीक स्ट्रिंग जनरेट करता है. आम तौर पर, आपको यह जानने की ज़रूरत नहीं होती कि वह स्ट्रिंग क्या है. ज़्यादातर कोडलैब में, आपको प्रोजेक्ट आईडी का रेफ़रंस देना होगा. आम तौर पर, इसे
PROJECT_ID
के तौर पर पहचाना जाता है. अगर आपको जनरेट किया गया आईडी पसंद नहीं है, तो कोई दूसरा आईडी जनरेट किया जा सकता है. इसके अलावा, आपके पास खुद से भी यह पता लगाने का विकल्प है कि यह सुविधा उपलब्ध है या नहीं. इस चरण के बाद, इसे बदला नहीं जा सकता. यह प्रोजेक्ट के दौरान बना रहेगा. - आपकी जानकारी के लिए बता दें कि तीसरी वैल्यू, प्रोजेक्ट नंबर होती है. इसका इस्तेमाल कुछ एपीआई करते हैं. दस्तावेज़ में इन तीनों वैल्यू के बारे में ज़्यादा जानें.
चेतावनी: प्रोजेक्ट आईडी दुनिया भर में यूनीक होता है. इसे चुनने के बाद, कोई दूसरा व्यक्ति इसका इस्तेमाल नहीं कर सकता. उस आईडी का इस्तेमाल सिर्फ़ आपने किया हो. प्रोजेक्ट मिटाने के बाद भी, आईडी का फिर से इस्तेमाल नहीं किया जा सकता
- इसके बाद, आपको Cloud के संसाधनों/एपीआई का इस्तेमाल करने के लिए, Cloud Console में बिलिंग की सुविधा चालू करनी होगी. इस कोडलैब को चलाने के लिए, आपसे कोई शुल्क नहीं लिया जाएगा. इस ट्यूटोरियल के बाद बिलिंग से बचने के लिए, बनाए गए संसाधनों को बंद किया जा सकता है या प्रोजेक्ट को मिटाया जा सकता है. Google Cloud के नए उपयोगकर्ता, 300 डॉलर के मुफ़्त ट्रायल वाले कार्यक्रम में शामिल हो सकते हैं.
Cloud Shell शुरू करना
Google Cloud को आपके लैपटॉप से रिमोट तौर पर इस्तेमाल किया जा सकता है. हालांकि, इस कोडलैब में आपको Google Cloud Shell का इस्तेमाल करना होगा. यह Cloud में चलने वाला कमांड-लाइन एनवायरमेंट है.
Google Cloud Console में, सबसे ऊपर दाएं टूलबार में मौजूद Cloud Shell आइकॉन पर क्लिक करें:
एनवायरमेंट से कनेक्ट होने और उसे प्रोवाइड करने में सिर्फ़ कुछ मिनट लगेंगे. इसके पूरा होने पर, आपको कुछ ऐसा दिखेगा:
इस वर्चुअल मशीन में, डेवलपमेंट के लिए ज़रूरी सभी टूल लोड होते हैं. यह 5 जीबी की होम डायरेक्ट्री उपलब्ध कराता है. यह Google Cloud पर चलता है, जिससे नेटवर्क की परफ़ॉर्मेंस और पुष्टि करने की सुविधा बेहतर होती है. इस कोडलैब में, सारा काम ब्राउज़र में किया जा सकता है. आपको कुछ भी इंस्टॉल करने की ज़रूरत नहीं है.
3. शुरू करने से पहले
एपीआई चालू करना
कृपया ध्यान रखें कि अगर प्रमोशनल टीयर का इस्तेमाल नहीं किया जा रहा है, तो चालू किए गए कुछ संसाधनों के लिए आपको शुल्क देना होगा. आम तौर पर, अगर प्रयोग पूरा होने के बाद सभी संसाधनों को नष्ट कर दिया जाता है, तो सभी संसाधनों की कीमत 5 डॉलर से ज़्यादा नहीं होगी. हमारा सुझाव है कि आप अपनी बिलिंग देखें और पक्का करें कि यह एक्सरसाइज़ आपके लिए सही है या नहीं.
Cloud Shell में, पक्का करें कि आपका प्रोजेक्ट आईडी सेट अप हो:
आम तौर पर, प्रोजेक्ट आईडी को क्लाउड शेल के कमांड प्रॉम्प्ट में ब्रैकेट में दिखाया जाता है, जैसा कि इस इमेज में दिखाया गया है:
gcloud config set project [YOUR-PROJECT-ID]
इसके बाद, एक विंडो पॉप-अप होगी. इसमें, Cloud Shell का इस्तेमाल करने की अनुमति मांगी जाएगी. कृपया अनुमति दें पर क्लिक करें
इसके बाद, 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. Postgres के लिए 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 नाम का VPC मौजूद है.
इंटरनल आईपी पता रिज़र्व करना
एनवायरमेंट वैरिएबल REGION में बताए गए GCP क्षेत्र में VPC सबनेट सीआईडीआर रेंज ढूंढें और Privat 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
ऊपर दी गई VPC सबनेट सीआईडीआर रेंज में, Private Service Connect एंडपॉइंट के लिए कोई इंटरनल आईपी पता रिज़र्व करें:
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].
पुष्टि करें कि इंटरनल आईपी पता रिज़र्व किया गया हो और आईपी पते के लिए 'रिज़र्व किया गया' स्टेटस दिख रहा हो.
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
सेवा के अटैचमेंट का यूआरआई पाना
Private Service Connect की सुविधा चालू करके Cloud SQL इंस्टेंस बनाने के बाद, सेवा अटैचमेंट का यूआरआई पाएं. इसके बाद, ऊपर दिए गए रिज़र्व किए गए इंटरनल आईपी पते का इस्तेमाल करके, 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 सेवा के अटैचमेंट यूआरआई पर ले जाएं:
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
डीएनएस से मैनेज किया जाने वाला ज़ोन कॉन्फ़िगर करना
Cloud SQL इंस्टेंस के लिए सुझाया गया डीएनएस नेम जोड़ने के लिए, उससे जुड़े वीपीएन नेटवर्क में निजी डीएनएस ज़ोन बनाना सबसे अच्छा होता है:
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 के लिए डीएनएस रिकॉर्ड जोड़ना
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.
सुझाए गए डीएनएस रिकॉर्ड को डीएनएस से मैनेज किए जाने वाले ज़ोन में जोड़ना
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 बनाएं, ताकि वीएम, 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 क्लाइंट सॉफ़्टवेयर इंस्टॉल करना
वीएम से कनेक्ट करने के लिए:
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'.
वीएम में सॉफ़्टवेयर चलाने का निर्देश इंस्टॉल करें:
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
कंपनी के डेटाबेस में मौजूद कर्मचारियों की टेबल में डेटा डालना
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 में, 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 एंडपॉइंट, रिज़र्व किया गया इंटरनल आईपी पता, डीएनएस रिकॉर्ड, और डीएनएस मैनेज किया गया ज़ोन.
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].
क्लाउड राऊटर मिटाएं:
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].
रिज़र्व किया गया इंटरनल आईपी पता रिलीज़ करें::
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].
डीएनएस रिकॉर्ड मिटाएं:
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].
डीएनएस से मैनेज किया जाने वाला ज़ोन मिटाना:
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 को डिप्लॉय करने का तरीका
- प्राइवेट सेवा कनेक्ट की मदद से, किसी वर्चुअल मशीन (VM) से Cloud SQL इंस्टेंस से कनेक्ट करने का तरीका