瞭解設定

設定是用來定義部署作業的結構。您必須指定設定才能建立部署作業。

在這個步驟中,您將存取建立具有兩個 Compute Engine 虛擬機器 (VM) 執行個體之部署的設定。VM 執行個體是可透過 Deployment Manager 部署的多種資源之一。

在這個步驟中,您將檢查具有兩個 VM 執行個體之部署的設定。

開啟 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-vmthe-second-vm。每個資源都有一個 nametypeproperties 欄位:

  • name:您為資源定義的名稱。

  • type:指定您要建立的資源類型。舉例來說,VM 可能是 compute.v1.instance。同樣地,Cloud SQL
    執行個體屬於 sql.v1beta4.instance 類型。

  • properties:指定資源屬性。建立資源所需的屬性與資源 API 要求的屬性相同。舉例來說,當您建立 Compute Engine VM 執行個體時,您必須提供機器類型、映像檔、網路介面,以及開機磁碟規格。

調整設定檔

two-vms.yaml 中,將 MY_PROJECT 替換為您的專案 ID。

# 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

儲存變更

只要擁有這個基本設定檔,即可建立第一個部署作業。在您宣告想要建立的資源後 (在本範例中為兩個屬於不同機器類型的 VM 執行個體),Deployment Manager 就會為您建立資源。

在下一個步驟中,您將使用這個設定來部署新資源。