Deployment Manager 基础知识

以下组件是 Deployment Manager 的基础。

配置

配置描述您希望为单个部署包括的所有资源。 配置是以 YAML 语法编写的文件,其中列出您要创建的每项资源及其各自的资源属性。配置必须包含 resources: 部分,后跟要创建的资源列表。

每项资源必须包含三个组成部分:

  • name - 用于标识此资源的用户定义字符串,如 my-vmproject-data-diskthe-test-network
  • type - 所部署资源的类型,如 compute.v1.instancecompute.v1.disk支持的资源类型文档中列出并介绍了基本资源类型。
  • properties - 此资源类型的参数。它们必须与类型的属性相匹配,如 zone: asia-east1-aboot: true

下面是一个示例配置:

resources:
- name: the-first-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/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/debian-7-wheezy-v20150423
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

模板

配置可以包含模板,模板在本质上是由配置文件的部分总结而来的一个个构成部分。创建模板后,您可以根据需要在多个部署中重复使用这些模板。 同样,如果您发现自己一直在重写有非常相似的属性的配置,则可以将共同部分总结为模板。模板比一个个单独的配置文件更为灵活,可支持在不同部署中轻松移植。

模板文件以 Python 或 Jinja2 编写。Deployment Manager 系统以递归方式解读每个模板,并将结果内嵌至配置文件。因此,每个模板的解读最终必将导致资源的 YAML 语法与上述为配置文件本身定义的语法相同。

要创建简单模板,请阅读创建基本模板

配置可描述为完全展开或未展开。完全展开的配置描述部署的所有资源和属性,包括导入模板文件中的任何内容。例如,使用模板的未展开配置可能如下所示:

imports:
- path: vm_template.jinja

resources:
- name: vm-instance
  type: vm_template.jinja
  properties:
    zone: us-central1-a
    project: myproject

展开后,配置文件将包含您的所有模板的内容,如下所示:

resources:
- name: the-first-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/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/debian-7-wheezy-v20150423
        networkInterfaces:
        - network: https