【问题标题】:Google Cloud Deployment Manager: add instances to instance group via yaml configurationGoogle Cloud Deployment Manager:通过 yaml 配置将实例添加到实例组
【发布时间】:2019-09-24 02:38:03
【问题描述】:

我正在尝试通过部署管理器配置(YAML 文件)创建一个包含多个 VM 的非托管 instanceGroup。

我可以通过 Google API 轻松找到有关 addInstances 的文档,但在 YAML 文件中找不到有关如何执行此操作的文档:

instances

instanceGroups

instances/instanceGroup 资源中应包含哪些属性才能使其正常工作?

【问题讨论】:

  • 您找到解决方法了吗?

标签: google-cloud-platform google-compute-engine google-cloud-sdk


【解决方案1】:

下面的 YAML 将创建一个计算引擎实例,创建一个非托管实例组,并将该实例添加到该组中。

resources:
- name: instance-1
  type: compute.v1.instance
  properties:
    zone: australia-southeast1-a
    machineType: zones/australia-southeast1-a/machineTypes/n1-standard-1
    disks:
    - deviceName: boot
      type: PERSISTENT
      diskType: zones/australia-southeast1-a/diskTypes/pd-ssd
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: projects/debian-cloud/global/images/debian-9-stretch-v20180716
    networkInterfaces:
    - network: global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

- name: ig-1
  type: compute.v1.instanceGroup
  properties:
    zone: australia-southeast1-a
    network: global/networks/default

- name: ig-1-members
  action: gcp-types/compute-v1:compute.instanceGroups.addInstances
  properties:
    project: YOUR_PROJECT_ID
    zone: australia-southeast1-a
    instanceGroup: ig-1
    instances: [ instance: $(ref.instance-1.selfLink) ]

【讨论】:

    【解决方案2】:

    目前不可能使用 gcloud 部署管理器来完成。

    【讨论】:

      【解决方案3】:

      这是经过测试的,似乎虽然 Google 部署管理器能够完成,但没有出现以下 sn-p 问题:

      {
        "instances":  [
          {
            "instance":  string
          }
        ]
      }
      

      它没有添加指定的实例,而是创建了 IGM。

      不过 Terraform 似乎能够做到这一点https://www.terraform.io/docs/providers/google/r/compute_instance_group.html

      【讨论】:

        【解决方案4】:

        我认为@mcourtney 的回答是正确的。

        我刚遇到这种情况,我使用带有 yaml 配置的 python 模板将实例添加到非托管实例组。

        这是我的python模板中资源定义的sn-p:

        {
                'name': name + '-ig-members',
                'action': 'gcp-types/compute-v1:compute.instanceGroups.addInstances',
                'properties': {
                    'project': '<YOUR PROJECT ID>',
                    'zone' : context.properties['zone'], // Defined in config yaml
                    'instanceGroup': '<YOUR Instance Group name ( not url )>',
                    "instances": [
            {
              "instance": 'projects/<PROJECT ID>/zones/<YOUR ZONE>/instances/<INSTANCE NAME>'
            }
          ]            
                }
            }
        

        参考 API 记录在这里:

        https://cloud.google.com/compute/docs/reference/rest/beta/instanceGroups/addInstances

        这只是一个例子。您可以将所有硬编码的内容抽象为 yaml 配置或 python 模板顶部的变量。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-11-10
          • 1970-01-01
          • 2018-12-02
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多