本文档介绍了如何在 Google Distributed Cloud (GDC) 网闸隔离配置中更新虚拟机 (VM) 实例属性。
您可以更新虚拟机属性,使虚拟基础设施与实例上运行的工作负载不断变化的需求保持一致。您可以增加 vCPU 或物理内存 (RAM),也可以减少它们,以便在项目中的其他位置重新分配资源。
您可以选择更新虚拟机的属性,而不是销毁虚拟机、重新构建虚拟机并迁移数据。虽然更新属性通常需要快速重启,但这种方法可以为您节省数小时的配置时间。
本文档适用于在 Distributed Cloud 环境中查看和更新虚拟机属性的平台管理员或应用运维人员群组中的开发者。如需了解详情,请参阅适用于 GDC 网闸隔离配置文档的受众群体。
准备工作
如需使用 gdcloud 命令行界面 (CLI) 命令,请确保您已下载、安装并配置 gdcloud CLI。Distributed Cloud 的所有命令都使用 gdcloud 或 kubectl CLI,并且需要操作系统 (OS) 环境。
获取 kubeconfig 文件路径
如需针对 Management API 服务器运行命令,请确保您拥有以下资源:
如果您没有 Management API 服务器的 kubeconfig 文件,请登录并生成该文件。
在这些说明中,请使用 Management API 服务器的 kubeconfig 文件的路径替换
MANAGEMENT_API_SERVER。
申请 IAM 角色
请与您的 IAM 项目管理员联系,请求在您的项目中授予以下角色:
Virtual Machine Project Admin (
project-vm-admin):在项目命名空间中创建、修改、列出和删除虚拟机。Project Viewer(
project-viewer):查看项目命名空间中的所有资源。
所有虚拟机角色都必须绑定到虚拟机所在项目的命名空间。 按照相关步骤验证您的访问权限。
可更新的属性
您只能更改虚拟机的 spec 中的属性。
查看可更新的属性
使用 GDC 控制台或 kubectl 查找要更改的属性。
控制台
在导航菜单中,点击虚拟机 > 实例。
在虚拟机列表中,点击虚拟机名称以查看其属性。
可修改的属性会显示 edit 修改图标。
kubectl
查看虚拟机
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. ...以递归方式查看每个媒体资源的子媒体资源。以下示例展示了
compute和vcpus子属性的返回值:以下示例命令会返回
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.
所有属性都可以在正在运行的虚拟机上更新,但通常需要重启虚拟机才能生效。
这些属性更新需要重启虚拟机才能使更改生效:
- 计算
- 磁盘
- 固件
- startupScripts
这些属性更新会立即生效:
- guestEnvironment
- runningState
更新虚拟机属性
使用 GDC 控制台或 kubectl 更新虚拟机属性。
控制台
kubectl
运行以下命令:
kubectl --kubeconfig MANAGEMENT_API_SERVER \ -n PROJECT \ edit virtualmachines.virtualmachine.gdc.goog VM_NAME替换下表中定义的变量。
变量 定义 MANAGEMENT_API_SERVERManagement API 服务器 kubeconfig 文件。 VM_NAME虚拟机的名称。 PROJECT项目名称。 修改
spec,以更新可更新属性的必填字段和值。保存文件。
如果属性更新需要重启虚拟机,请按照重启虚拟机说明重启虚拟机。