הסבר על הגדרות

ההגדרה מגדירה את מבנה הפריסה. כדי ליצור פריסה, צריך לציין הגדרה.

בשלב הזה, תיגשו להגדרה שיוצרת פריסה עם שתי מכונות וירטואליות (VM) של Compute Engine. מכונת VM היא אחד מכמה סוגים של משאבים שאפשר לפרוס באמצעות Deployment Manager.

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

פותחים את קובץ ה-YAML של ההגדרות

עוברים לספרייה שיצרתם בקטע התקנה והגדרה:

cd deploymentmanager-samples/examples/v2/step_by_step_guide/step2_create_a_configuration

לאחר מכן, פותחים את two-vms.yaml:

nano two-vms.yaml   # use your preferred text editor

בקטע resources, שימו לב שיש שני משאבים: the-first-vm ו-the-second-vm. לכל משאב יש שדה name, type וproperties:

  • name: שם שאתם מגדירים למשאב.

  • type: מציין את סוג המשאב שאתם יוצרים. לדוגמה, מכונה וירטואלית היא compute.v1.instance. באופן דומה, מופע של Cloud SQL
    הוא מסוג sql.v1beta4.instance.

  • properties: מציין את מאפייני המשאב. המאפיינים שנדרשים ליצירת המשאב הם אותם מאפיינים שנדרשים על ידי ה-API של המשאב. לדוגמה, כשיוצרים מכונה וירטואלית ב-Compute Engine, צריך לספק סוג מכונה, תמונה, ממשק רשת ומפרט של דיסק אתחול.

הגדרת קובץ התצורה

ב-two-vms.yaml, מחליפים את MY_PROJECT במזהה הפרויקט.

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

resources:
- name: the-first-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-f
    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:
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT
- name: the-second-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-f
    machineType: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/zones/us-central1-f/machineTypes/g1-small
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-11
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/MY_PROJECT/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

שומרים את השינויים.

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

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