【问题标题】:How to create an instance with local ssd attached with gcp如何使用 gcp 附加本地 ssd 创建实例
【发布时间】:2020-08-11 08:20:18
【问题描述】:

我尝试使用 python googleapiclient 创建一个带有启动盘和本地 ssd 盘的实例。 这是构建系统的 gcp 映像,我想要更好的性能

def create_instance(compute, image_name):
    image_response = compute.images().get(project=GCP_PROJECT_ID,
                                          image=GCP_IMAGE_NAME).execute()
    source_disk_image = image_response['selfLink']
    machine_type = f"zones/{GCP_ZONE}/machineTypes/n2-standard-4"
    config = {
        'name': image_name,
        'machineType': machine_type,

        # Specify the boot disk and the image to use as a source.
        'disks': [
            {
                'boot': True,
                'autoDelete': True,
                'initializeParams': {
                    'sourceImage': source_disk_image,
                }
            },
            {
                'boot': False,
                'autoDelete': True,
                'initializeParams': {
                    'disk_type': 'local-ssd'
                }
            }
        ],

        # Specify a network interface with NAT to access the public
        # internet.
        'networkInterfaces': [{
            'network': 'global/networks/default',
            'accessConfigs': [
                {'type': 'ONE_TO_ONE_NAT', 'name': 'External NAT'}
            ]
        }],

        # Allow the instance to access cloud storage and logging.
        'serviceAccounts': [{
            'email': 'default',
            'scopes': [
                "https://www.googleapis.com/auth/cloud-platform"
            ]
        }]
    }

    operation = compute.instances().insert(
        project=GCP_PROJECT_ID,
        zone=GCP_ZONE,
        body=config).execute()
    return operation

作为。很难我尝试给不同的 initializeParams diskTypes 它总是为我创建一个标准的持久 500GB 磁盘而不是本地 ssd。我已经试过了:

但没有任何帮助。

我做错了什么?

【问题讨论】:

    标签: google-cloud-platform


    【解决方案1】:

    使用official GCP documentation创建具有本地SSD的实例,并参考谷歌的API,我们可以查看以下内容:

    除了上述信息之外,以下是一个示例请求负载,它创建了一个带有启动磁盘和本地 SSD 设备的实例:

    与您使用 Python Google 的 API 客户端的负载请求相比,您似乎没有指定每个磁盘的“类型”。 API 要求本地 SSD 输入“SCRATCH”,而可引导磁盘需要输入“PERSISTENT”。尝试这样做,看看它是否有任何影响。

    【讨论】:

      【解决方案2】:

      作为文档 [1,本地 SSD 位于运行您的虚拟机实例的物理机上,它们只能在实例创建过程中创建。本地 SSD 不能用作启动设备。

      创建本地 SSD 后,我们必须在使用之前格式化并挂载设备 [2]。

      [1]https://cloud.google.com/compute/docs/disks/local-ssd#create_local_ssd

      [2]https://cloud.google.com/compute/docs/disks/local-ssd#format_and_mount_a_local_ssd_device

      【讨论】:

      • 我在这里发出一个实例创建命令。我作为参数传递可引导为假。我的代码有什么问题?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 2019-11-21
      • 2019-12-13
      相关资源
      最近更新 更多