本页面介绍了您可以为现有虚拟机更新哪些虚拟机 (VM) 属性,以及如何执行此类更新。
准备工作
如需使用 gdcloud
命令行界面 (CLI) 命令,请确保您已下载、安装并配置 gdcloud
CLI。Distributed Cloud 的所有命令都使用 gdcloud
或 kubectl
CLI,并且需要操作系统 (OS) 环境。
获取 kubeconfig 文件路径
如需针对管理 API 服务器运行命令,请确保您拥有以下资源:
登录并生成管理 API 服务器的 kubeconfig 文件(如果您还没有)。
使用管理 API 服务器的 kubeconfig 文件路径替换这些说明中的
MANAGEMENT_API_SERVER
。
请求权限和访问权限
如需执行本页面中列出的任务,您必须具有 Project VirtualMachine Admin 角色。按照相关步骤验证您是否在虚拟机所在项目的命名空间中拥有 Project VirtualMachine Admin (project-vm-admin
) 角色。
对于使用 GDC 控制台或 gdcloud CLI 的虚拟机操作,请让您的项目 IAM 管理员为您分配“Project VirtualMachine Admin”角色和“Project Viewer”角色 (project-viewer
)。
可更新的属性
您只能更改虚拟机的 spec
中的属性。
查看可更新的属性
使用 GDC 控制台或 kubectl
查找要更改的媒体资源。
控制台
在导航菜单中,依次点击 Virtual Machines > Instances。
在虚拟机列表中,点击某个虚拟机的名称以查看其属性。
可修改的属性带有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 \ edit virtualmachines.virtualmachine.gdc.goog VM_NAME \ -n PROJECT
替换下表中定义的变量。
变量 定义 MANAGEMENT_API_SERVER
管理 API 服务器 kubeconfig 文件。 VM_NAME
虚拟机的名称。 PROJECT
项目名称。 修改
spec
以更新可更新属性所需的字段和值。保存文件。
如果属性更新需要重启虚拟机,请按照重启虚拟机说明重启虚拟机。