【问题标题】:GCP create an instance template from an existing VMGCP 从现有虚拟机创建实例模板
【发布时间】:2020-10-09 20:10:21
【问题描述】:

我正在尝试从现有的已关闭虚拟机创建实例模板。 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

【问题讨论】:

  • 设备名称更像是人类使用的符号链接。据我所知,/dev 中的条目是自动的。有关示例,请参阅this article。
  • 你能分享源实例的细节吗?例如使用此命令gcloud compute instances describe ajm-centos8
  • 根据您的推荐使用描述数据编辑帖子。谢谢。

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


【解决方案1】:

为了能够将安装在您的虚拟机上的任何程序保留到您的实例模板中,您必须使用您在原始实例中使用的映像创建实例模板。

按照以下步骤从您的原始实例创建图像:

  1. 转到控制台菜单 > Compute Engine > 图像。
  2. 点击Create Image。
  3. 为您的图片提供Name。
  4. 选择Image 为Source。
  5. 点击创建。

从这里,您可以使用创建的映像创建您的实例模板,并且将保留该映像上预安装的所有应用程序。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2022-08-02
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      相关资源
      最近更新 更多