ניהול Google Cloud משאבים כפריסה

אתם יכולים להשתמש ב-Google Cloud Deployment Manager כדי ליצור קבוצה של משאבי Google Cloud ולנהל אותם כיחידה אחת שנקראת פריסה. לדוגמה, אם בסביבת הפיתוח של הצוות שלכם נדרשות שתי מכונות וירטואליות (VM) ומסד נתונים של BigQuery, אתם יכולים להגדיר את המשאבים האלה בקובץ הגדרות ולהשתמש ב-Deployment Manager כדי ליצור, לשנות או למחוק אותם. אפשר להוסיף את קובץ התצורה למאגר המקורות של הקוד של הצוות, כדי שכל אחד יוכל ליצור את אותה סביבה עם תוצאות עקביות.

במדריך הזה תשתמשו ב-Google Cloud Deployment Manager כדי ליצור מופע של מכונה וירטואלית (VM). תגדירו את המכונה הווירטואלית בקובץ תצורה בסיסי, ותשתמשו בקובץ התצורה הזה כדי ליצור פריסה.

כדי להשלים את המדריך הזה, אתם צריכים לדעת איך להריץ פקודות במסוף של Linux,‏ macOS או Windows.

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

מדריך למתחילים ב-Cloud Shell

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

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

  6. מפעילים את ממשקי ה-API של Deployment Manager ו-Compute Engine.

    תפקידים שנדרשים להפעלת ממשקי API

    כדי להפעיל ממשקי API, צריך את תפקיד ה-IAM 'אדמין של Service Usage' (roles/serviceusage.serviceUsageAdmin), שכולל את ההרשאה serviceusage.services.enable. איך מקצים תפקידים

    הפעלת ממשקי ה-API

  7. בתחנת העבודה, מתקינים את Google Cloud CLI.
  8. מגדירים את Google Cloud CLI לשימוש בפרויקט. בפקודה הבאה, מחליפים את [MY_PROJECT] במזהה הפרויקט:
    gcloud config set project [MY_PROJECT]

הגדרת המשאבים

אתם מתארים את המשאבים בקובץ הגדרה שנכתב בתחביר YAML.

  1. מעתיקים את תצורת הדוגמה שבהמשך ומדביקים אותה בעורך טקסט.

    # Copyright 2016 Google Inc. All rights reserved.
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    
    # Put all your resources under `resources:`. For each resource, you need:
    # - The type of resource. In this example, the type is a Compute VM instance.
    # - An internal name for the resource.
    # - The properties for the resource. In this example, for VM instances, you add
    #   the machine type, a boot disk, network information, and so on.
    #
    # For a list of supported resources,
    # see https://cloud.google.com/deployment-manager/docs/configuration/supported-resource-types.
    resources:
    - type: compute.v1.instance
      name: quickstart-deployment-vm
      properties:
        # The properties of the resource depend on the type of resource. For a list
        # of properties, see the API reference for the resource.
        zone: us-central1-f
        # Replace [MY_PROJECT] with your project ID
        machineType: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/zones/us-central1-f/machineTypes/f1-micro
        disks:
        - deviceName: boot
          type: PERSISTENT
          boot: true
          autoDelete: true
          initializeParams:
            # See a full list of image families at https://cloud.google.com/compute/docs/images#os-compute-support
            # The format of the sourceImage URL is: https://www.googleapis.com/compute/v1/projects/[IMAGE_PROJECT]/global/images/family/[FAMILY_NAME]
            sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11
        # Replace [MY_PROJECT] with your project ID
        networkInterfaces:
        - network: https://www.googleapis.com/compute/v1/projects/[MY_PROJECT]/global/networks/default
          # Access Config required to give the instance a public IP address
          accessConfigs:
          - name: External NAT
            type: ONE_TO_ONE_NAT
    

    קובץ ההגדרות הבסיסי הזה מתאר פריסה שמכילה מופע של מכונה וירטואלית עם המאפיינים הבאים:

    • סוג המכונה: f1-micro
    • משפחת תמונות: debian-11
    • אזור: us-central1-f
    • דיסק אחסון מתמיד (persistent disk) בסיסי: boot
    • כתובת IP חיצונית שהוקצתה באופן אקראי
  2. מחליפים את כל המופעים של [MY_PROJECT] במזהה הפרויקט.

  3. שומרים את הקובץ בפורמט vm.yaml.

פריסת המשאבים

כדי לפרוס את המשאבים, משתמשים ב-Google Cloud CLI כדי ליצור פריסה חדשה באמצעות קובץ התצורה:

gcloud deployment-manager deployments create quickstart-deployment --config vm.yaml

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

Create operation operation-1432319707382-516afeb5d00f1-b864f0e7-b7103978 completed successfully.
NAME                    TYPE                STATE      ERRORS
quickstart-deployment   compute.v1.instance COMPLETED  -

עכשיו יש לך פריסה ראשונה!

בדיקת הפריסה החדשה

כדי לבדוק את סטטוס הפריסה, מריצים את הפקודה הבאה:

gcloud deployment-manager deployments describe quickstart-deployment

יוצג תיאור של הפריסה, כולל שעת ההתחלה ושעת הסיום שלה, המשאבים שנוצרו ואזהרות או שגיאות (אם יש):

fingerprint: xmVVeTtPq-5rr8F-vWFlrg==
id: '54660732508021769'
insertTime: '2016-03-09T04:45:26.032-08:00'
manifest: https://www.googleapis.com/deploymentmanager/v2/projects/myproject/global/deployments/my-first-deployment/manifests/manifest-1457527526037
name: quickstart-deployment
operation:
  endTime: '2016-03-09T04:46:19.480-08:00'
  id: '8993923014899639305'
  kind: deploymentmanager#operation
  name: operation-1457527525951-52d9d126f4618-f1ca6e72-3404bd3b
  operationType: insert
  progress: 100
  startTime: '2016-03-09T04:45:27.275-08:00'
  status: DONE
...
resources:
NAME                     TYPE                 STATE      ERRORS
quickstart-deployment-vm  compute.v1.instance  COMPLETED  -

בדיקת המשאבים

אחרי שיוצרים את הפריסה, אפשר לבדוק את המשאבים במסוףGoogle Cloud .

  1. כדי לראות רשימה של הפריסות, פותחים את הדף Deployment Manager.

    מעבר אל Deployment Manager

  2. כדי לראות את המשאבים בפריסה, לוחצים על quickstart-deployment. תיפתח סקירה כללית של הפריסה, עם מידע על הפריסה ועל המשאבים שכלולים בה.

  3. כדי לראות מידע על המכונה הווירטואלית, לוחצים על quickstart-deployment-vm.

הסרת המשאבים

כדי לא לצבור חיובים לחשבון Google Cloud על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים:

gcloud deployment-manager deployments delete quickstart-deployment

מקלידים y בהנחיה:

The following deployments will be deleted:
- quickstart-deployment

Do you want to continue (y/N)?

הפריסה והמשאבים שיצרתם נמחקים באופן סופי.

המאמרים הבאים