【问题标题】:How to update machine type property through GCP deployment manager如何通过 GCP 部署管理器更新机器类型属性
【发布时间】:2018-05-04 08:15:58
【问题描述】:

我有一个如下所示的用于计算实例类型的 python 模板以及其他所需的 config.yaml 文件。

... CONTROLLER_MACHINE_TYPE='n1-standard-8' controller_template = { 'name': 'controller-it', 'type': 'it_template.py', 'properties': { 'machineType': CONTROLLER_MACHINE_TYPE, 'dockerImage': CONTROLLER_IMAGE, 'dockerEnv': { 'ADC_LISTEN_QUEUE': 'controller-subscriber' }, 'zone': ZONE, 'network': NETWORK_NAME, 'saEmail': SA_EMAIL } }

it_template.py 内容

def GenerateConfig(context):
    resources = [{
        'name': context.env['name'],
        'type': 'compute.v1.instanceTemplate',
        'properties': {
            'zone': context.properties['zone'],
            'properties': {
                "machineType": context.properties['machineType'],
                "metadata": {
                    "items": [{
                        "key": 'gce-container-declaration',
                        "value": GenerateManifest(context)
                    }]
                }, ...

我已经将它部署到名为 qa 的环境中。现在一段时间后,我意识到我需要更改此实例的机器类型。例如,我希望我的 qa 环境更新此资源的机器类型,而不是 n1-standard-8。

但是我没有看到任何提到更新任何资源属性的示例。

我们可以使用 gcp 部署管理器更新环境中资源的属性吗? 或者我需要添加具有其他名称和所需机器类型属性的新资源?

更新

按照@jordi Miralles 的建议,我修改了我的模板,将 machineType 设为 n1-standard-16 并尝试更新部署。

但我得到以下错误

cloud deployment-manager deployments update qa --config dm_config.yaml The fingerprint of the deployment is KkD38j9KYiBTiaIW8SltbA== Waiting for update [operation-1525444590548-56b623ef1b421-b4733efd-53174d1b]...failed.
ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1525444590548-56b623ef1b421-b4733efd-53174d1b]: errors: - code: NO_METHOD_TO_UPDATE_FIELD message: No method found to update field 'properties' on resource 'controller-it' of type 'compute.v1.instanceTemplate'. The resource may need to be recreated with the new field.

请帮忙。

【问题讨论】:

    标签: google-cloud-platform google-deployment-manager


    【解决方案1】:

    您可以在部署管理器中更新资源,如果您想更改资源,则无需创建具有不同名称的新资源。见updating a deployment

    您可以将现有部署 yaml 文件与您要应用的更改一起使用,然后更新现有部署:

    gcloud deployment-manager deployments update [EXISTING DEPLOYMENT] --config [UPDATED YAML]
    

    考虑到您的实例必须停止。对changing machine type 的所有其他影响适用。此外,您的任何永久性磁盘上的数据都不会丢失。

    记得在更新完成后开启实例!

    【讨论】:

    • 感谢您的回复。正如建议的那样,我更新了部署但得到了错误。我已经在上面的主要内容中更新了它。
    • 看看这个来自 serverfault 的答案,它可能对你有用:serverfault.com/questions/726490/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    相关资源
    最近更新 更多