更新虚拟机属性

本文档介绍如何在 Google Distributed Cloud (GDC) 气隙环境中更新虚拟机 (VM) 实例属性。

您可以更新虚拟机属性,使虚拟基础架构与实例上运行的工作负载不断变化的需求保持一致。您可以增加或减少 vCPU 或物理内存 (RAM),以便在项目的其他位置重新分配资源。

您可以选择更新虚拟机属性,而不是销毁虚拟机、重建虚拟机和迁移数据。虽然更新属性通常需要快速重启,但这种方法可以为您节省数小时的配置时间。

本文档适用于平台管理员或应用运维人员组中的开发者,他们可以在 Distributed Cloud 环境中查看和更新虚拟机属性。如需了解详情,请参阅 GDC 网闸隔离配置文档的受众

准备工作

如需使用 gdcloud 命令行界面 (CLI) 命令,请确保您已下载、安装、 并配置 gdcloud CLI。 Distributed Cloud 的所有命令都使用 gdcloudkubectl CLI,并且需要操作系统 (OS) 环境。

获取 kubeconfig 文件路径

如需针对 Management API 服务器运行命令,请确保您拥有以下资源:

  1. 登录并生成 Management API 服务器的 kubeconfig 文件(如果您没有)。

  2. 使用 Management API 服务器的 kubeconfig 文件的路径替换这些说明中的 MANAGEMENT_API_SERVER

请求 IAM 角色

请与您的项目 IAM 管理员联系,以请求对您的项目具有以下角色:

  • 虚拟机项目管理员 (project-vm-admin):在项目命名空间中创建、修改、列出和删除虚拟机。

  • 项目查看者(project-viewer):查看项目命名空间中的所有资源。

所有虚拟机角色都必须绑定到虚拟机所在项目的命名空间。 请按照以下步骤验证 您的访问权限。

可更新的属性

您只能更改虚拟机 spec 中的属性。

查看可更新的属性

使用 GDC 控制台或 kubectl 查找要更改的属性。

控制台

  1. 在导航菜单中,点击虚拟机 > 实例

  2. 在虚拟机列表中,点击虚拟机名称以查看其属性。

  3. 可修改的属性具有 修改 图标。

kubectl

  1. 查看虚拟机 spec 的属性列表以及每个属性对应的有效值:

    kubectl --kubeconfig MANAGEMENT_API_SERVER \
      explain virtualmachines.virtualmachine.gdc.goog.spec
    

    输出类似于以下内容:

    KIND:     VirtualMachine
    VERSION:  virtualmachine.gdc.goog/v1
    
    RESOURCE: spec <Object>
    
    DESCRIPTION:
         Defines the specification of the Virtual Machine.
    
    FIELDS:
       compute      <Object>
         Specifies the CPU and Memory of the VM. CPU and Memory can be defined
         directly or through the VirtualMachineType. Changes to Compute require a
         reboot to take effect. Compute is immutable when the VM is in `Unknown`
         state.
    
       disks        <[]Object> -required-
         Specifies the list of disks attached to this vm. There must be exactly one
         boot disk. Changes to disk attachments require a reboot to take effect.
    
       ...
    
  2. 以递归方式查看每个属性的子属性。以下示例展示了 computevcpus 子属性的返回结果:

    • 此示例命令返回 compute 子属性的字段:

      kubectl --kubeconfig MANAGEMENT_API_SERVER \
        explain virtualmachines.virtualmachine.gdc.goog.spec.compute
      

      输出类似于以下内容:

      KIND:     VirtualMachine
      VERSION:  virtualmachine.gdc.goog/v1
      
      RESOURCE: compute <Object>
      
      DESCRIPTION:
           Specifies the CPU and Memory of the VM. CPU and Memory can be defined
           directly or through the VirtualMachineType. Changes to Compute require a
           reboot to take effect. Compute is immutable when the VM is in `Unknown`
           state.
      
      FIELDS:
         memory       <>
           Specifies the amount of physical memory available to the instance. memory
           must have a minimum value of `1G`, and can be up to (including) `400G`.
      
         vcpus        <integer>
           Specifies the number of VCPUs that are available to the instance. Specify
           `vcpus` as an integer. This value must be a multiple of 2, with 2 as the
           minimum and 128 as the maximum allowed.
      
         ...
      
    • 此示例命令返回 vcpus 子属性的字段:

      kubectl --kubeconfig MANAGEMENT_API_SERVER \
        explain virtualmachines.virtualmachine.gdc.goog.spec.compute.vcpus
      

      输出类似于以下内容:

      KIND:     VirtualMachine
      VERSION:  virtualmachine.gdc.goog/v1
      
      FIELD:    vcpus <integer>
      
      DESCRIPTION:
           Specifies the number of VCPUs that are available to the instance. Specify
           `vcpus` as an integer. This value must be a multiple of 2, with 2 as the
           minimum and 128 as the maximum allowed.
      

所有属性都可以在正在运行的虚拟机上更新,但通常需要重启虚拟机才能生效。

以下属性更新需要重启虚拟机才能使更改生效:

以下属性更新会立即生效:

  • guestEnvironment
  • runningState

更新虚拟机属性

使用 GDC 控制台或 kubectl 更新虚拟机属性。

控制台

  1. 在导航菜单中,点击虚拟机 > 实例

  2. 在虚拟机列表中,点击虚拟机名称以查看其属性。

  3. 点击要修改的属性旁边的 修改 并进行更改。

  4. 如果要替换启动磁盘或添加新磁盘,请参阅 替换启动磁盘向虚拟机添加磁盘

  5. 点击保存

kubectl

  1. 运行以下命令:

    kubectl --kubeconfig MANAGEMENT_API_SERVER \
       -n PROJECT \
       edit virtualmachines.virtualmachine.gdc.goog VM_NAME
    

    替换下表中定义的变量。

    变量定义
    MANAGEMENT_API_SERVERManagement API 服务器 kubeconfig 文件。
    VM_NAME虚拟机的名称。
    PROJECT项目名称。
  2. 修改 spec 以更新可更新属性的必填字段和值。

  3. 保存文件。

  4. 如果属性更新需要重启虚拟机, 请按照重启虚拟机 中的说明重启虚拟机。