Deployment Manager 无法更新实例模板 - NO_METHOD_TO_UPDATE_FIELD

Deployment Manager cannot update instance templates - NO_METHOD_TO_UPDATE_FIELD

我有一个包含托管实例组和两个实例模板(A 和 B)的部署。部署最初是使用引用实例模板 A 的实例组创建的。

我尝试使用部署管理器更新实例模板 B 中的 sourceImage (gcloud beta deployment-manager deployments update my-deployment --template ...),但得到以下信息错误:

ERROR: (gcloud.beta.deployment-manager.deployments.update) Error in 
Operation [operation-1538798895713-57787898f4ae9-8b478716-0bb72a09]: 
errors:
- code: NO_METHOD_TO_UPDATE_FIELD
  message: No method found to update field 'properties' on 
  resource 'fwp-app-preprod-instance-template-a' of type 
  'compute.v1.instanceTemplate'. The resource may need to be
  recreated with the new field.

我应该说清楚,我对原始部署所做的唯一更改是实例模板的 sourceImage。

是否可以通过部署管理器执行实例模板更新,以便它引用更新的 sourceImage?

该错误清楚地表明可能需要重新创建资源(实例模板),我很高兴部署管理器可以这样做。但我不知道如何 instruct/force 部署管理器采取该行动。

我不怀疑它可以在部署管理器之外完成,但我想避免配置漂移。

我的app.jinja.schema:

imports:
- path: instance-group.jinja
- path: instance-template.jinja

我的app.jinja:

resources:
- name: instance-template-a
  type: instance-template.jinja
  properties:
    name: {{ env["deployment"] }}-instance-template-a
    machineType: g1-small
    sourceImage: "projects/my-project/global/images/my-image"
    diskSizeGb: '30'

- name: instance-template-b
  type: instance-template.jinja
  properties:
    name: {{ env["deployment"] }}-instance-template-b
    machineType: g1-small
    sourceImage: "projects/my-project/global/images/my-image"
    diskSizeGb: '30'

- name: fwp-instance-group
  type: instance-group.jinja

我的实例-group.jinja:

resources:
- name: 'instance-group-{{ env["deployment"] }}'
  type: compute.v1.regionInstanceGroupManager
  properties:
    baseInstanceName: ig-instance-{{ env["deployment"] }}
    instanceTemplate: '$(ref.{{ env["deployment"] }}-instance-template-a.selfLink)'
    targetSize: 1
    region: australia-southeast1

- name: 'autoscaler-{{ env["deployment"] }}'
  type: compute.v1.regionAutoscalers
  properties:
    autoscalingPolicy:
      coolDownPeriodSec: 60
      loadBalancingUtilization:
        utilizationTarget: 0.9
      maxNumReplicas: 10
      minNumReplicas: 2
    target: $(ref.instance-group-{{ env["deployment"] }}.selfLink)
    region: australia-southeast1

还有我的实例-template.jinja

resources:
- name: {{ properties["name"] }}
  type: compute.v1.instanceTemplate
  properties:
    name: {{ properties["name"] }}
    description: ''
    properties:
      machineType: {{ properties["machineType"] }}
      tags:
        items:
        - no-ip
        - web-server
        - http-server
        - https-server
      disks:
      - type: 'PERSISTENT'
        boot: true
        mode: 'READ_WRITE'
        autoDelete: true
        deviceName: instance-device
        initializeParams:
          sourceImage: {{ properties["sourceImage"] }}
          diskType: 'pd-standard'
          diskSizeGb: {{ properties["diskSizeGb"] }}
      canIpForward: false
      networkInterfaces:
      - network: projects/my-project/global/networks/vpc-fwp-nonprod
        subnetwork: projects/my-project/regions/australia-southeast1/subnetworks/subnet-private-fwp-nonprod
        aliasIpRanges: []
      labels: { environment: {{ env["deployment"] }}, tenancy: "fwp-nonprod" }
      scheduling:
        preemptible: false
        onHostMaintenance: MIGRATE
        automaticRestart: true
        nodeAffinities: []
      serviceAccounts:
      - email: some-service-account@developer.gserviceaccount.com
        scopes:
        - https://www.googleapis.com/auth/cloud-platform

回顾评论:

DM 配置包括托管实例组的实例模板。更改源图像试图更改模板中使用的图像。

不幸的是,instance templates are immutable once created

"So it is not possible to update an existing instance template or change an instance template after it has been created."

这解释了返回的错误消息。更改要用于托管实例组的图像的正确方法是创建一个新模板并对组执行 rolling update 并使用新实例模板。