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

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

בשלב הזה, תיגשו להגדרה שיוצרת פריסה עם שתי מכונות וירטואליות (VM) של Compute Engine. מכונה וירטואלית היא אחד מכמה סוגי משאבים שאפשר לפרוס באמצעות 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 דואג ליצור את המשאבים.

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