ממשק Private Service Connect ב-Vertex AI Pipelines

1. מבוא

ממשק Private Service Connect הוא משאב שמאפשר לרשת של ענן וירטואלי פרטי (VPC) של בעלי שירות ליזום חיבורים ליעדים שונים ברשת של צרכן. רשתות של יצרנים וצרכנים יכולות להיות בפרויקטים ובארגונים שונים.

חיבור בין קובץ מצורף עם הרשת לבין ממשק Private Service Connect דומה לחיבור בין נקודת קצה של Private Service Connect לבין קובץ מצורף עם השירות, אבל יש שני הבדלים עיקריים:

  • קובץ מצורף של רשת מאפשר לרשת של ספק ליזום חיבורים לרשת של צרכן (תעבורת נתונים יוצאת (egress) של שירות מנוהל), ואילו נקודת קצה מאפשרת לרשת של צרכן ליזום חיבורים לרשת של ספק (תעבורת נתונים נכנסת (ingress) של שירות מנוהל).
  • חיבור ממשק Private Service Connect הוא טרנזיטיבי. המשמעות היא שרשת של יצרן יכולה לתקשר עם רשתות אחרות שמחוברות לרשת של הצרכן.

מה תפַתחו

‫Vertex AI Pipelines, שנפרס בפרויקט דיירים מנוהל של Google, ינצל את קובץ ה-PSC Network Attachment כדי ליצור מופע עם כמה כרטיסי רשת בין רשת היצרן לרשת הצרכן. מכיוון ש-PSC Network Attachment נפרס עם כרטיס רשת מרובה מרשת הצרכן, Vertex AI Pipelines יכולה להגיע למסלולים שזמינים מרשת הצרכן.

במדריך הזה, תיצרו ארכיטקטורה מקיפה של ממשק Private Service Connect ‏ (PSC) ל-Vertex AI Pipelines, שמשתמשת בכללי Cloud Firewall כדי לאפשר או לחסום קישוריות מהיצרן למופעי הבדיקה של הצרכן, כמו שמוצג באיור 1.

איור 1

12714b6f0f8fa411.png

תיצרו קובץ יחיד של psc-network-attachment ב-VPC של הצרכן, וכתוצאה מכך יתקבלו תרחישי השימוש הבאים:

  1. יוצרים כלל חומת אש לתעבורת נתונים נכנסת ב-VPC של הלקוח שמאפשר לרשת המשנה של Vertex AI Pipeline‏ (192.168.10.0/28) לגשת אל test-svc-1. אישור של PING מוצלח שנוצר ממשימת ה-Pipeline אל test-svc-1 באמצעות TCPDUMP
  2. יוצרים כלל חומת אש לדחיית תעבורת נתונים נכנסת (ingress) ב-VPC של הלקוח כדי לדחות את רשת המשנה של Vertex AI Pipeline ‏(192.168.10.0/28) אל test-svc-2. מאשרים שה-PING נכשל על סמך יומני חומת האש שנוצרו על ידי Log Explorer.

מה תלמדו

  • איך יוצרים קובץ מצורף לרשת
  • איך אפשר להשתמש ב-Vertex AI Pipelines כדי ליצור ממשק PSC באמצעות קובץ מצורף לרשת
  • איך יוצרים תקשורת מהמפיק לצרכן
  • איך מאפשרים גישה מ-Vertex AI Pipelines למכונה הווירטואלית של הלקוח, test-svc-1
  • איך חוסמים גישה מ-Vertex AI Pipelines למכונת ה-VM של הצרכן, test-svc-2, באמצעות Cloud Firewall

מה תצטרכו

‫2. לפני שמתחילים

במדריך הזה נעשה שימוש ב-$variables כדי לעזור בהטמעה של הגדרות gcloud ב-Cloud Shell.

ב-Cloud Shell, מבצעים את הפעולות הבאות:

gcloud config list project
gcloud config set project [YOUR-PROJECT-NAME]
projectid=YOUR-PROJECT-NAME
echo $projectid

עדכון הפרויקט כדי לתמוך במדריך

ב-Cloud Shell, מבצעים את הפעולות הבאות:

gcloud services enable notebooks.googleapis.com
gcloud services enable aiplatform.googleapis.com
gcloud services enable compute.googleapis.com
gcloud services enable cloudresourcemanager.googleapis.com

3. הגדרת צרכן

יצירת VPC של צרכן

ב-Cloud Shell, מבצעים את הפעולות הבאות:

gcloud compute networks create consumer-vpc --project=$projectid --subnet-mode=custom

יצירת רשתות משנה לצרכנים

ב-Cloud Shell, מבצעים את הפעולות הבאות:

gcloud compute networks subnets create test-subnet-1 --project=$projectid --range=192.168.20.0/28 --network=consumer-vpc --region=us-central1

ב-Cloud Shell, מבצעים את הפעולות הבאות:

gcloud compute networks subnets create test-subnet-2 --project=$projectid --range=192.168.30.0/28 --network=consumer-vpc --region=us-central1

ב-Cloud Shell, מבצעים את הפעולות הבאות:

gcloud compute networks subnets create workbench-subnet --project=$projectid --range=192.168.40.0/28 --network=consumer-vpc --region=us-central1 --enable-private-ip-google-access

הגדרות של Cloud Router ו-NAT

במדריך נעשה שימוש ב-Cloud Network Address Translation (NAT) להורדות של חבילות תוכנה של מחברות, כי למופע המחברת אין כתובת IP חיצונית. ‫Cloud NAT מציע יכולות NAT ליציאה, כלומר למארחים באינטרנט אסור ליזום תקשורת עם מחברת שמנוהלת על ידי המשתמש, מה שהופך אותה למאובטחת יותר.

ב-Cloud Shell, יוצרים את Cloud Router האזורי.

gcloud compute routers create cloud-router-us-central1 --network consumer-vpc --region us-central1

ב-Cloud Shell, יוצרים את שער Cloud NAT האזורי.

gcloud compute routers nats create cloud-nat-us-central1 --router=cloud-router-us-central1 --auto-allocate-nat-external-ips --nat-all-subnet-ip-ranges --region us-central1

יצירת תת-רשת של קובץ מצורף לרשת של Private Service Connect

ב-Cloud Shell, יוצרים את רשת המשנה Network Attachment שמשמשת את Vertex AI Pipelines.

gcloud compute networks subnets create intf-subnet --project=$projectid --range=192.168.10.0/28 --network=consumer-vpc --region=us-central1

4. הפעלת שרת proxy לאימות זהויות (IAP)

כדי לאפשר ל-IAP להתחבר למכונות הווירטואליות, צריך ליצור כלל חומת אש ש:

  • רלוונטי לכל מכונות ה-VM שרוצים לגשת אליהן באמצעות IAP.
  • מאפשר תנועה נכנסת מטווח כתובות ה-IP‏ 35.235.240.0/20. הטווח הזה מכיל את כל כתובות ה-IP שמשמשות את IAP להעברת TCP.

ב-Cloud Shell, יוצרים את הכלל בחומת האש של IAP.

gcloud compute firewall-rules create ssh-iap-consumer \
    --network consumer-vpc \
    --allow tcp:22 \
    --source-ranges=35.235.240.0/20

5. יצירת מכונות וירטואליות לצרכנים

ב-Cloud Shell, יוצרים את מופע ה-VM של הצרכן, test-svc-1.

gcloud compute instances create test-svc-1 \
    --project=$projectid \
    --machine-type=e2-micro \
    --image-family debian-11 \
    --no-address \
    --image-project debian-cloud \
    --zone us-central1-a \
    --subnet=test-subnet-1 \
    --shielded-secure-boot

ב-Cloud Shell, יוצרים את מופע המכונה הווירטואלית של הצרכן, test-svc-2.

gcloud compute instances create test-svc-2 \
    --project=$projectid \
    --machine-type=e2-micro \
    --image-family debian-11 \
    --no-address \
    --image-project debian-cloud \
    --zone us-central1-a \
    --subnet=test-subnet-2 \
    --shielded-secure-boot

משיגים ושומרים את כתובות ה-IP של המופעים:

ב-Cloud Shell, מריצים פקודת describe על מכונות ה-VM של הבדיקה.

gcloud compute instances describe test-svc-1 --zone=us-central1-a | grep  networkIP:

gcloud compute instances describe test-svc-2 --zone=us-central1-a | grep  networkIP:

דוגמה:

user@cloudshell(psc-vertex)$ gcloud compute instances describe test-svc-1 --zone=us-central1-a | grep  networkIP:

gcloud compute instances describe test-svc-2 --zone=us-central1-a | grep  networkIP:
  networkIP: 192.168.20.2
  networkIP: 192.168.30.2

6. קובץ מצורף עם הרשת של Private Service Connect

קובצי מצורפים עם הרשת הם משאבים אזוריים שמייצגים את הצד של הצרכן בממשק Private Service Connect. משייכים תת-רשת אחת לקובץ מצורף לרשת, והבעלים (Vertex AI Pipelines) מקצה כתובות IP לממשק Private Service Connect.

יצירת קובץ מצורף לרשת

ב-Cloud Shell, יוצרים את קובץ הרשת המצורף.

gcloud compute network-attachments create psc-network-attachment \
    --region=us-central1 \
    --connection-preference=ACCEPT_MANUAL \
    --subnets=intf-subnet

הצגת הקבצים המצורפים לרשת

ב-Cloud Shell, מציגים את רשימת קבצים מצורפים לרשת.

gcloud compute network-attachments list

תיאור של קבצים מצורפים לרשת

ב-Cloud Shell, מתארים את הרשת המצורפת.

gcloud compute network-attachments describe psc-network-attachment --region=us-central1

חשוב לשים לב ל-URI של psc-network-attachment שבו ישתמש הבעלים של השירות המנוהל כשהוא ייצור את הממשק של Private Service Connect.

בדוגמה הבאה, ה-URI של קובץ ה-attachment לרשת PSC הוא:

projects/psc-vertex/regions/us-central1/networkAttachments/psc-network-attachment

user@cloudshell$ gcloud compute network-attachments describe psc-network-attachment --region=us-central1
connectionPreference: ACCEPT_MANUAL
creationTimestamp: '2025-01-21T12:25:25.385-08:00'
fingerprint: m9bHc9qnosY=
id: '56224423547354202'
kind: compute#networkAttachment
name: psc-network-attachment
network: https://www.googleapis.com/compute/v1/projects/psc-vertex/global/networks/consumer-vpc
region: https://www.googleapis.com/compute/v1/projects/psc-vertex/regions/us-central1
selfLink: https://www.googleapis.com/compute/v1/projects/psc-vertex/regions/us-central1/networkAttachments/psc-network-attachment
subnetworks:
- https://www.googleapis.com/compute/v1/projects/psc-vertex/regions/us-central1/subnetworks/intf-subnet

7. הגדרה של Vertex AI Workbench

בקטע הבא מוסבר איך ליצור Jupyter Notebook. המחברת הזו תשמש לפריסת משימת Pipelines ששולחת PING מ-Vertex AI Pipelines למופעי הבדיקה. נתיב הנתונים בין Vertex AI Pipelines לבין רשת הצרכן שמכילה את המופעים משתמש בממשק רשת של Private Service Connect.

יצירה של חשבון שירות שמנוהל על ידי משתמש

בקטע הבא תיצרו חשבון שירות שישויך למופע Vertex AI Workbench שבו נעשה שימוש במדריך.

במדריך הזה, התפקידים הבאים יוקצו לחשבון השירות:

ב-Cloud Shell, יוצרים את חשבון השירות.

gcloud iam service-accounts create notebook-sa \
    --display-name="notebook-sa"

ב-Cloud Shell, מעדכנים את חשבון השירות עם התפקיד Storage Admin (אדמין אחסון).

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:notebook-sa@$projectid.iam.gserviceaccount.com" --role="roles/storage.admin"

ב-Cloud Shell, מעדכנים את חשבון השירות עם התפקיד Vertex AI User.

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:notebook-sa@$projectid.iam.gserviceaccount.com" --role="roles/aiplatform.user"

ב-Cloud Shell, מעדכנים את חשבון השירות עם התפקיד Artifact Registry Admin.

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:notebook-sa@$projectid.iam.gserviceaccount.com" --role="roles/artifactregistry.admin"

ב-Cloud Shell, מאפשרים לחשבון השירות של מחברת ה-Notebook להשתמש בחשבון השירות שמוגדר כברירת מחדל של Compute Engine כדי ליצור מופע של משימת צינור עיבוד הנתונים.

gcloud iam service-accounts add-iam-policy-binding \
    $(gcloud projects describe $(gcloud config get-value project) --format='value(projectNumber)')-compute@developer.gserviceaccount.com \
    --member="serviceAccount:notebook-sa@$projectid.iam.gserviceaccount.com" \
    --role="roles/iam.serviceAccountUser"

יצירת מופע של Vertex AI Workbench

בקטע הבא, יוצרים מכונה של Vertex AI Workbench שמשלבת את חשבון השירות שיצרתם קודם, notebook-sa.

ב-Cloud Shell, יוצרים את המכונה private-client.

gcloud workbench instances create workbench-tutorial --vm-image-project=deeplearning-platform-release --vm-image-family=common-cpu-notebooks --machine-type=n1-standard-4 --location=us-central1-a --subnet-region=us-central1 --subnet=workbench-subnet --disable-public-ip --shielded-secure-boot=true --service-account-email=notebook-sa@$projectid.iam.gserviceaccount.com

8. ‫Vertex AI Pipelines לבדיקת הקישוריות של test-svc-1

פותחים כרטיסייה חדשה ב-Cloud Shell ומעדכנים את הגדרות הפרויקט.

ב-Cloud Shell, מבצעים את הפעולות הבאות:

gcloud config list project
gcloud config set project [YOUR-PROJECT-NAME]
projectid=YOUR-PROJECT-NAME
echo $projectid

כדי לאפשר קישוריות מ-Vertex AI Pipelines אל test-svc-1, יוצרים כללי חומת אש לכניסה שמציינים את קובץ ה-PSC Network Attachment כמקור (192.168.10.0/28) ואת כתובת ה-IP של test-svc-1 כיעד.

ב-Cloud Shell, מעדכנים את destination-range כך שיתאים לכתובת ה-IP של test-svc-1.

gcloud compute --project=$projectid firewall-rules create allow-icmp-vertex-pipelines-to-test-svc1-vm --direction=INGRESS --priority=1000 --network=consumer-vpc --action=ALLOW  --source-ranges=192.168.10.0/28 --destination-ranges=<your-test-svc-1-vm-ip> --rules=icmp

דוגמה:

gcloud compute --project=$projectid firewall-rules create allow-icmp-vertex-pipelines-to-test-svc1-vm --direction=INGRESS --priority=1000 --network=consumer-vpc --action=ALLOW  --source-ranges=192.168.10.0/28 --destination-ranges=192.168.20.2 --rules=icmp

מתחברים למופע test-svc-1 באמצעות IAP ב-Cloud Shell.

gcloud compute ssh test-svc-1 --project=$projectid --zone=us-central1-a --tunnel-through-iap

במערכת ההפעלה, מריצים את הפקודה tcpdump כדי לתעד תעבורת ICMP. סשן מערכת ההפעלה הזה ישמש לאימות התקשורת בין Vertex AI Pipeline לבין המכונה הווירטואלית.

sudo tcpdump -i any icmp -nn

9. עדכון של סוכן השירות של Vertex AI

‫Vertex AI Pipelines פועל בשמכם כדי לבצע פעולות כמו קבלת כתובת IP מרשת המשנה של קובץ ה-PSC Network Attachment שמשמש ליצירת ממשק ה-PSC. לשם כך, Vertex AI Pipelines משתמש בסוכן שירות (שמופיע בהמשך) שנדרשת לו הרשאת אדמין רשת.

service-$projectnumber@gcp-sa-aiplatform.iam.gserviceaccount.com

ב-Cloud Shell, מאתרים את מספר הפרויקט.

gcloud projects describe $projectid | grep projectNumber

דוגמה:

gcloud projects describe $projectid | grep projectNumber:
projectNumber: '795057945528'

ב-Cloud Shell, מעדכנים את חשבון סוכן השירות עם התפקיד compute.networkAdmin.

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:service-<your-projectnumber>@gcp-sa-aiplatform.iam.gserviceaccount.com" --role="roles/compute.networkAdmin"

דוגמה:

gcloud projects add-iam-policy-binding $projectid --member="serviceAccount:service-795057945528@gcp-sa-aiplatform.iam.gserviceaccount.com" --role="roles/compute.networkAdmin"

10. עדכון חשבון השירות שמוגדר כברירת מחדל

מפעילים את Compute Engine API ונותנים לחשבון השירות שמוגדר כברירת מחדל גישה ל-Vertex AI. חשוב לזכור: יכול להיות שיעבור זמן עד שהשינוי בהרשאות יתעדכן.

ב-Cloud Shell, מעדכנים את חשבון השירות שמוגדר כברירת מחדל לתפקיד aiplatform.user.

gcloud projects add-iam-policy-binding $projectid \
  --member="serviceAccount:<your-projectnumber>-compute@developer.gserviceaccount.com" \
    --role="roles/aiplatform.user"

דוגמה:

gcloud projects add-iam-policy-binding $projectid \
  --member="serviceAccount:795057945528-compute@developer.gserviceaccount.com" \
    --role="roles/aiplatform.user"

11. פריסת משימה של Vertex AI Pipelines

בקטע הבא ניצור מחברת כדי לבצע PING מוצלח למופע test-svc-1 של הצרכן.

מריצים את משימת האימון במכונת Vertex AI Workbench.

  1. במסוף Google Cloud, עוברים לכרטיסייה Instances (מופעים) בדף Vertex AI Workbench.
  2. לצד השם של מופע Vertex AI Workbench (workbench-tutorial), לוחצים על Open JupyterLab. המכונה של Vertex AI Workbench תיפתח ב-JupyterLab.
  3. בוחרים באפשרות 'קובץ' > 'חדש' > 'מחברת'.
  4. בוחרים באפשרות Kernel (ליבה) > Python 3.
  5. בתא חדש במחברת, מריצים את הפקודה הבאה כדי לוודא שיש לכם את הגרסה העדכנית של pip:
! pip3 install --upgrade --quiet google-cloud-aiplatform \
  kfp \
  google-cloud-pipeline-components
  1. הגדרת משתני הפרויקט בתא החדש של ה-Notebook
PROJECT_ID = "<your-projectid>" 
REGION = "<your-region>"  
NETWORK_ATTACHMENT_NAME = "psc-network-attachment"

דוגמה:

PROJECT_ID = "psc-vertex" 
REGION = "us-central1"  
NETWORK_ATTACHMENT_NAME = "psc-network-attachment"
  1. הגדרת שם ייחודי של מאגר כמשתנה בתא חדש של מחברת
BUCKET_URI = f"gs://<your-bucket-name>"

דוגמה:

BUCKET_URI = f"gs://psc-vertex-bucket"
  1. יוצרים את הקטגוריה בתא חדש ב-Notebook
! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}

בקטע הבא תגדירו את חשבון השירות המוגדר כברירת מחדל ב-Compute Engine שבו ישתמשו כדי להריץ את עבודת צינור עיבוד הנתונים, ותעניקו לו את ההרשאות המתאימות.

shell_output = ! gcloud projects describe $PROJECT_ID
PROJECT_NUMBER = shell_output[-1].split(":")[1].strip().replace("'", "")
SERVICE_ACCOUNT = f"{PROJECT_NUMBER}-compute@developer.gserviceaccount.com"

print(f"Project Number: {PROJECT_NUMBER}")
print(f"Service Account: {SERVICE_ACCOUNT}")

כדי לוודא שההפעלה בוצעה בהצלחה, מספר הפרויקט ומספר חשבון השירות מודפסים

  1. בתא חדש של מחברת, מעניקים לחשבון השירות הרשאה לקרוא ולכתוב ארטיפקטים של צינורות ב-bucket שנוצר בשלב הקודם.
! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectCreator {BUCKET_URI}

! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.objectViewer {BUCKET_URI}
  1. בתא חדש במחברת, מגדירים את הפרמטרים של צינור העיבוד. הערה: NETWORK_ATTACHMENT_NAME הוא שם הקובץ המצורף לרשת PSC, ולכן הוא חייב להיות זהה.
PIPELINE_ROOT = f"{BUCKET_URI}/pipeline_root/psc_test"
NETWORK_ATTACHMENT_URI = f"projects/{PROJECT_NUMBER}/regions/{REGION}/networkAttachments/{NETWORK_ATTACHMENT_NAME}"
  1. בתא חדש של notebook, מאתחלים את Vertex AI SDK
from kfp import dsl
from google.cloud import aiplatform, aiplatform_v1beta1
import time
from google.cloud.aiplatform_v1.types import pipeline_state
import yaml
from datetime import datetime
import logging
aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
  1. בתא חדש ב-Notebook, מגדירים את רכיב הבדיקה
@dsl.container_component
def ping_check(network_address: str):
    """Pings a network address

    Args:
        network_address: The IP address to ping
    """

    return dsl.ContainerSpec(
        image="ubuntu:22.04",
        command=["sh", "-c"],
        args=[
            f"""
            
            # Use sed for regex replacement, cleaner than bash parameter expansion for this
            cleaned_address=$(echo "{network_address}" | sed 's/[^0-9.]//g')
            apt-get update && apt-get install inetutils-traceroute inetutils-ping -y
            
            echo "Will ping $cleaned_address"
            if ! ping -c 3 $cleaned_address; then
                echo "Ping failed"
                traceroute -w 1 -m 7 $cleaned_address
                exit 1
            fi
            """
        ],
    )
  1. מגדירים את צינור הנתונים בתא חדש ב-Notebook
@dsl.pipeline(name="check-connectivity")
def pipeline(ip_address: str):
    """Pings an IP address. Facilitated by a Private Service Connect Interface

    Args:
        ip_address: The IP address to ping
    """
    ping_check(network_address=ip_address).set_caching_options(False)
    return
  1. בתא חדש במחברת, מריצים את הפונקציה הבסיסית, וממתינים לסיום הצינור.
def wait_for_pipeline(
    project_id: str,
    region: str,
    pipeline_job_resource_name: str,
    timeout: int = 20 * 60,  # Default timeout of 20 minutes (in seconds)
) -> bool:
    """
    Waits for a Vertex AI pipeline to finish, with a timeout.

    Args:
        project_id (str): The Google Cloud project ID.
        region (str): The region where the pipeline is running.
        pipeline_job_resource_name (str): The resource name of the pipeline job.
        timeout (int): The maximum time to wait for the pipeline to finish, in seconds.
                       Defaults to 20 minutes (1200 seconds).

    Returns:
        bool: True if the pipeline succeeded, False otherwise.

    Raises:
        TimeoutError: If the pipeline does not finish within the specified timeout.
    """

    # Initialize the AIPlatform client
    aiplatform.init(project=project_id, location=region)

    # Get the pipeline job
    pipeline_job = aiplatform.PipelineJob.get(resource_name=pipeline_job_resource_name)
    logging.info(
        f"Vertex AI Console Link: https://console.cloud.google.com/vertex-ai/pipelines/locations/{region}/runs/{pipeline_job.resource_name.split('/')[-1]}?project={project_id}"
    )

    start_time = time.time()
    while True:
        status = pipeline_job.state
        logging.info(f"Pipeline Job status: {status.name}")

        if status in [
            pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED,
            pipeline_state.PipelineState.PIPELINE_STATE_FAILED,
            pipeline_state.PipelineState.PIPELINE_STATE_CANCELLED,
        ]:
            break  # Exit the loop if the job is finished

        if time.time() - start_time > timeout:
            logging.error(f"Pipeline timed out after {timeout} seconds.")
            raise TimeoutError(f"Pipeline timed out after {timeout} seconds.")
        
        # Wait for a short time before checking again
        time.sleep(10)  # Adjust the wait time as needed

    # Do something based on the final status
    if status == pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED:
        logging.info("Pipeline succeeded")
        return True
    elif status == pipeline_state.PipelineState.PIPELINE_STATE_CANCELLED:
        logging.error("Pipeline cancelled")
        raise Exception("Pipeline cancelled")
    elif status == pipeline_state.PipelineState.PIPELINE_STATE_FAILED:
        logging.error("Pipeline failed")
        raise Exception("Pipeline failed")
  1. בתא חדש של מחברת, מריצים את הפונקציה הבסיסית כדי להריץ את צינור העיבוד.
def run_job_with_psc_interface_config(
    project_id: str,
    region: str,
    pipeline_root: str,
    network_attachment_name: str,
    ip_address: str,
    local_pipeline_file: str = "pipeline.yaml",
):
    """
    Compiles, submits, and monitors a Vertex AI pipeline.
    """

    parameter_values = {"ip_address": ip_address}
    pipeline_root = f"{pipeline_root}/{datetime.now().strftime('%Y%m%d%H%M%S')}"
    logging.info("Compiling pipeline")

    try:
        with open(local_pipeline_file, "r") as stream:
            pipeline_spec = yaml.safe_load(stream)
            logging.info(f"Pipeline Spec: {pipeline_spec}")
    except yaml.YAMLError as exc:
        logging.error(f"Error loading pipeline yaml file: {exc}")
        raise
    
    logging.info(f"Will use pipeline root: {pipeline_root}")
    # Initialize the Vertex SDK using PROJECT_ID and LOCATION
    aiplatform.init(project=project_id, location=region)

    # Create the API endpoint
    client_options = {"api_endpoint": f"{region}-aiplatform.googleapis.com"}

    # Initialize the PipelineServiceClient
    client = aiplatform_v1beta1.PipelineServiceClient(client_options=client_options)

    # Construct the request
    request = aiplatform_v1beta1.CreatePipelineJobRequest(
        parent=f"projects/{project_id}/locations/{region}",
        pipeline_job=aiplatform_v1beta1.PipelineJob(
            display_name="pipeline-with-psc-interface-config",
            pipeline_spec=pipeline_spec,
            runtime_config=aiplatform_v1beta1.PipelineJob.RuntimeConfig(
                gcs_output_directory=pipeline_root, parameter_values=parameter_values
            ),
            psc_interface_config=aiplatform_v1beta1.PscInterfaceConfig(
                network_attachment=network_attachment_name
            ),
        ),
    )

    # Make the API call
    response = client.create_pipeline_job(request=request)

    # Print the response
    logging.info(f"Pipeline job created: {response.name}")

    return response.name
  1. בתא חדש ב-Notebook, מהדרים את צינור עיבוד הנתונים.
from kfp import compiler
compiler.Compiler().compile(pipeline_func=pipeline, package_path='pipeline.yaml')
  1. בתא חדש של מחברת, מעדכנים את TARGET_IP_ADDRESS כך שישקף את כתובת ה-IP שהתקבלה בשלב הקודם עבור test-svc-1, ומתבוננים בסטטוס של משימת הצינור.
TARGET_IP_ADDRESS = "<your-test-svc-1-ip>"
try:
    job_name = run_job_with_psc_interface_config(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_root=PIPELINE_ROOT,
        network_attachment_name=NETWORK_ATTACHMENT_URI,
        ip_address=TARGET_IP_ADDRESS,
    )
    wait_for_pipeline(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_job_resource_name=job_name,
    )
except Exception as e:
    logging.error(f"An error occurred: {e}")

דוגמה:

TARGET_IP_ADDRESS = "192.168.20.2"
try:
    job_name = run_job_with_psc_interface_config(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_root=PIPELINE_ROOT,
        network_attachment_name=NETWORK_ATTACHMENT_URI,
        ip_address=TARGET_IP_ADDRESS,
    )
    wait_for_pipeline(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_job_resource_name=job_name,
    )
except Exception as e:
    logging.error(f"An error occurred: {e}")

אחרי שמבצעים את שלב 17, צינור הנתונים יימשך כ-8 דקות.

12. אימות הקישוריות אל test-svc-1

בתא שבו השתמשתם כדי להריץ את שלב 17, בודקים את המעבר של סטטוס עבודת הצינור מ-PIPELINE_STATE_PENDING ל-PIPELINE_STATE_RUNNING ובסופו ל-PIPELINE_STATE_SUCCEEDED, שמציין שה-ping מ-Vertex AI Pipelines הצליח והתקבלה תשובה מ-test-svc-1.

כדי לאמת את תעבורת ICMP בין Vertex AI Pipeline לבין test-svc-1, צופים בסשן tcpdump שנוצר קודם והופעל במערכת ההפעלה של test-svc-1. הסשן הזה מספק יומנים שמציינים תעבורה דו-כיוונית.

בדוגמה של tcpdump, מערכת Vertex AI Pipelines מקבלת את כתובת ה-IP‏ 192.168.10.3 מתת-הרשת 192.168.10.0/28, ו-192.168.20.2 היא כתובת ה-IP של test-svc-1. שימו לב, כתובות ה-IP עשויות להיות שונות בסביבה שלכם.

user@test-svc-1:~$ sudo tcpdump -i any icmp -nn
tcpdump: data link type LINUX_SLL2
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
18:57:54.737490 ens4  In  IP 192.168.10.3 > 192.168.20.2: ICMP echo request, id 257, seq 0, length 64
18:57:54.737523 ens4  Out IP 192.168.20.2 > 192.168.10.3: ICMP echo reply, id 257, seq 0, length 64

13. ‫Vertex AI Pipelines AI to test-svc-2 connectivity

בקטע הבא, תיצרו כלל חומת אש לכניסה כדי לדחות תעבורה מתת-רשת של Vertex AI Pilelines ‏ (192.168.10.0/28) אל test-svc-2. לאחר מכן תעדכנו את המחברת כך שתשקף את כתובת ה-IP של test-svc-2, ולבסוף תפעילו את הריצה של משימות ה-Pipelines.

בתא של מחברת ה-Notebook, סטטוס עבודת הצינור יציין שגיאה – הצינור נכשל. בנוסף, יומני חומת האש יספקו תובנות לגבי החיבור שנכשל.

יצירת כלל חומת אש לדחייה של תעבורת נתונים נכנסת (ingress)

כדי לחסום את הקישוריות מ-Vertex AI Pipelines אל test-svc-2, יוצרים כלל חומת אש לכניסה שמציין את קובץ ה-PSC Network Attachment כמקור (192.168.10.0/28) ואת כתובת ה-IP של test-svc-2 כיעד.

ב-Cloud Shell, מעדכנים את destination-range כך שיתאים לכתובת ה-IP של test-svc-2.

gcloud compute --project=$projectid firewall-rules create deny-icmp-vertex-pipelines-to-test-svc2-vm --direction=INGRESS --priority=1000 --network=consumer-vpc --action=DENY  --source-ranges=192.168.10.0/28 --rules=ALL --destination-ranges=<your-test-svc-2-vm-ip> --rules=icmp --enable-logging

דוגמה:

gcloud compute --project=$projectid firewall-rules create deny-icmp-vertex-pipelines-to-test-svc2-vm --direction=INGRESS --priority=1000 --network=consumer-vpc --action=DENY  --source-ranges=192.168.10.0/28 --rules=ALL --destination-ranges=192.168.30.2 --enable-logging

הפעלת משימה של צינור עיבוד נתונים מתא ב-Notebook

בתא חדש במחברת, מעדכנים את TARGET_IP_ADDRESS כך שישקף את כתובת ה-IP שהתקבלה בשלב הקודם עבור test-svc-2, ומתבוננים בסטטוס של משימת ה-Pipelines.

TARGET_IP_ADDRESS = "<your-test-svc-2-ip>"
try:
    job_name = run_job_with_psc_interface_config(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_root=PIPELINE_ROOT,
        network_attachment_name=NETWORK_ATTACHMENT_URI,
        ip_address=TARGET_IP_ADDRESS,
    )
    wait_for_pipeline(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_job_resource_name=job_name,
    )
except Exception as e:
    logging.error(f"An error occurred: {e}")

דוגמה:

TARGET_IP_ADDRESS = "192.168.30.2"
try:
    job_name = run_job_with_psc_interface_config(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_root=PIPELINE_ROOT,
        network_attachment_name=NETWORK_ATTACHMENT_URI,
        ip_address=TARGET_IP_ADDRESS,
    )
    wait_for_pipeline(
        project_id=PROJECT_ID,
        region=REGION,
        pipeline_job_resource_name=job_name,
    )
except Exception as e:
    logging.error(f"An error occurred: {e}")

אחרי ההפעלה, עבודת הצינור תסתיים תוך 8 דקות בערך.

14. אימות הקישוריות אל test-svc-2 נכשל

בתא שבו השתמשתם כדי להריץ את משימת הצינורות, שימו לב למעבר הסטטוס מ-PIPELINE_STATE_PENDING ל-PIPELINE_STATE_FAILED, שמציין פינג לא מוצלח מ-Vertex AI Pipelines ותגובה מ-test-svc-2.

באמצעות Log Explorer אפשר לראות רשומות של רישום ביומן של חומת האש שתואמות לכלל הדחייה של תעבורת נכנסת, שכולל את רשת המשנה של Vertex AI Pipelines ‏ (192.168.10.0/28) ואת כתובת ה-IP של test-svc-2.

בוחרים באפשרות 'הצגת שאילתה', מזינים את המסנן שלמטה, last 15 minutes (15 הדקות האחרונות), ואז לוחצים על 'הפעלת שאילתה'.

jsonPayload.rule_details.reference:("network:consumer-vpc/firewall:deny-icmp-vertex-pipelines-to-test-svc2-vm")

20e072f26d9a113b.png

5fb3d2de0a85e3c6.png

בוחרים רשומה ביומן, מרחיבים את השדות המקוננים כדי לחשוף את רכיבי המידע שכוללים את Vertex AI Pipelines ואת כתובת ה-IP של test-svc-2 שמאמתת את כלל חומת האש של תעבורת הכניסה שנדחתה.

903aaf2c10d07460.png

15. הסרת המשאבים

ב-Cloud Shell, מוחקים את רכיבי ההדרכה.

gcloud compute instances delete test-svc-1 test-svc-2 --zone=us-central1-a --quiet

gcloud workbench instances delete workbench-tutorial --location=us-central1-a --quiet

gcloud compute firewall-rules delete deny-icmp-vertex-pipelines-to-test-svc2-vm allow-icmp-vertex-pipelines-to-test-svc1-vm ssh-iap-consumer --quiet

gcloud compute routers nats delete cloud-nat-us-central1 --router=cloud-router-us-central1 --region us-central1 --quiet

gcloud compute routers delete cloud-router-us-central1 --region=us-central1 --quiet

16. מזל טוב

ברכות, הגדרתם ואימתתם בהצלחה ממשק Private Service Connect וקישוריות של צרכן וספק על ידי הטמעה של חומת אש עם כללי אישור וכניסה.

יצרתם את תשתית הצרכן והוספתם קובץ מצורף לרשת שמאפשר לשירות Vertex AI Pipelines ליצור מכונה וירטואלית של ממשק PSC כדי לגשר על התקשורת בין הצרכן לבין היצרן. למדתם איך ליצור כללי חומת אש ברשת ה-VPC של הצרכן, שמאפשרים או חוסמים קישוריות למופעים ברשת הצרכן.

‫Cosmopup חושב שסרטוני הדרכה הם מדהימים!!

c911c127bffdee57.jpeg

מה השלב הבא?

קריאה נוספת וסרטונים

מאמרי עזרה