了解配置

配置定义了部署的结构。您必须指定配置才能创建部署。

在此步骤中,您将访问可创建带有两个 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-vmthe-second-vm。每个资源都有 nametypeproperties 字段:

  • name:您为资源定义的名称。

  • type:指定要创建的资源的类型。例如,虚拟机为 compute.v1.instance。同样,Cloud SQL
    实例的类型为 sql.v1beta4.instance

  • properties:指定资源的属性。创建资源所需的属性与相应资源的 API 所需的属性相同。例如,创建 Compute Engine 虚拟机实例时,您必须提供机器类型、映像、网络接口和启动磁盘规范。

设置配置文件

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

保存更改

创建首个部署只需要此基本配置文件。您已经声明了要创建的资源(在本示例中为两个具有不同机器类型的虚拟机实例),Deployment Manager 负责创建资源。

在下一步中,您将使用此配置来部署新资源。