本頁說明現有 VM 可更新的虛擬機器 (VM) 屬性,以及如何執行這類更新。
事前準備
如要使用 gdcloud
指令列介面 (CLI) 指令,請務必下載、安裝及設定 gdcloud
CLI。Distributed Cloud 的所有指令都使用 gdcloud
或 kubectl
CLI,且需要作業系統 (OS) 環境。
取得 kubeconfig 檔案路徑
如要對 Management API 伺服器執行指令,請確認您具備下列資源:
登入並產生 Management API 伺服器的 kubeconfig 檔案 (如果沒有)。
使用 Management API 伺服器的 kubeconfig 檔案路徑,取代這些操作說明中的
MANAGEMENT_API_SERVER
。
要求權限和存取權
如要執行本頁列出的工作,您必須具備專案虛擬機器管理員角色。按照步驟驗證您在 VM 所在專案的命名空間中,是否具備專案 VirtualMachine 管理員 (project-vm-admin
) 角色。
如要使用 GDC 控制台或 gdcloud CLI 執行 VM 作業,請要求專案 IAM 管理員同時指派專案 VirtualMachine 管理員角色和專案檢視者 (project-viewer
) 角色。
可更新的屬性
您只能變更 VM 的 spec
屬性。
查看可更新的屬性
使用 GDC 控制台或 kubectl
找出要變更的屬性。
主控台
在導覽選單中,依序點選「Virtual Machines」>「Instances」。
在 VM 清單中,按一下 VM 名稱即可查看其屬性。
可編輯的屬性會顯示「編輯」圖示 edit。
kubectl
查看 VM
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.
所有屬性都可以在執行中的 VM 上更新,但通常需要重新啟動 VM 才會生效。
更新這些屬性後,必須重新啟動 VM,變更才會生效:
- 運算
- 磁碟
- 韌體
- startupScripts
下列屬性更新會立即生效:
- guestEnvironment
- runningState
更新 VM 屬性
使用 GDC 控制台或 kubectl
更新 VM 屬性。
主控台
kubectl
執行下列指令:
kubectl --kubeconfig MANAGEMENT_API_SERVER \ edit virtualmachines.virtualmachine.gdc.goog VM_NAME \ -n PROJECT
請根據下表定義替換變數。
變數 定義 MANAGEMENT_API_SERVER
管理 API 伺服器 kubeconfig 檔案。 VM_NAME
VM 名稱。 PROJECT
專案名稱。 編輯
spec
,更新可更新屬性的必要欄位和值。儲存檔案。
如果更新屬性需要重新啟動 VM,請按照「重新啟動 VM」一節的說明操作。