GCP从现有VM创建实例模板

时间:2020-10-09 20:10:21

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

我正在尝试从现有的已关闭电源的VM创建实例模板。 VM是一个非常基本的Centos Linux机器。搜寻了一下问题之后,我想到了以下内容,但是我不知道如何格式化磁盘设备名称。我找不到很多例子。在此先感谢您对这个问题的理解。

$gcloud compute instance-templates create plainid-pocv12-cent8-autostart --source-instance ajm-centos8 --configure-disk=device-name=/dev/sda,instantiate-from=source-image,auto-delete=true

ERROR: (gcloud.compute.instance-templates.create) Could not fetch resource:
 - Invalid value for field 'resource.sourceInstanceParams.diskConfigs[0].deviceName': '/dev/sda'. Device name specified in disk instantiation config not found in source instance: '/dev/sda'.

根据以下建议,我进行了描述。看起来设备名称也是'ajm-centos8'

$gcloud compute instances describe ajm-centos8
canIpForward: false
confidentialInstanceConfig:
  enableConfidentialCompute: false
cpuPlatform: Intel Haswell
creationTimestamp: '2020-10-05T06:04:50.611-07:00'
deletionProtection: false
description: ''
disks:
- autoDelete: true
  boot: true
  deviceName: ajm-centos8
  diskSizeGb: '30'
  guestOsFeatures:
  - type: UEFI_COMPATIBLE
  - type: VIRTIO_SCSI_MULTIQUEUE
  - type: SEV_CAPABLE
  index: 0
  interface: SCSI
  kind: compute#attachedDisk
  licenses:
  - https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-8
  mode: READ_WRITE
  source: https://www.googleapis.com/compute/v1/projects/plainid-presales/zones/us-east1-b/disks/ajm-centos8
  type: PERSISTENT

所以现在我正在运行以下命令。它会创建一个模板!但是,新模板没有在原始VM上安装的任何软件。

$gcloud compute instance-templates create plainid-pocv12-cent8-autostart --source-instance ajm-centos8 --configure-disk=device-name=ajm-centos8,instantiate-from=source-image,auto-delete=true
Created [https://www.googleapis.com/compute/v1/projects/plainid-presales/global/instanceTemplates/plainid-pocv12-cent8-autostart].
NAME                            MACHINE_TYPE                   PREEMPTIBLE  CREATION_TIMESTAMP
plainid-pocv12-cent8-autostart  custom (e2, 2 vCPU, 6.00 GiB)               2020-10-09T13:55:02.563-07:00

1 个答案:

答案 0 :(得分:0)

实例模板基本上用于定义和保存机器配置,例如机器类型,启动磁盘映像或容器映像,标签以及其他实例属性。然后,该模板可立即用于创建单个VM或MIG。您可以查看Instance templates了解更多详细信息。

creating an instance template based on an existing instance的文档在这里看起来很有帮助。在此文档中,您可以查看用于替代如何在模板中定义磁盘的选项。