更新 VM 屬性

本文說明如何在 Google Distributed Cloud (GDC) 實體隔離環境中,更新虛擬機器 (VM) 執行個體屬性。

您可以更新 VM 屬性,讓虛擬基礎架構符合執行個體上工作負載的變化需求。您可以增加 vCPU 或實體記憶體 (RAM),也可以減少這些資源,將資源重新分配到專案中的其他位置。

您可以選擇更新 VM 的屬性,而不必刪除 VM、重新建構 VM 並遷移資料。雖然更新屬性通常需要快速重新啟動,但這種方法可以節省數小時的設定時間。

本文件適用於平台管理員或應用程式操作員群組中的開發人員,他們會在 Distributed Cloud 環境中查看及更新 VM 屬性。詳情請參閱「GDC 實體隔離方案說明文件的目標對象」。

事前準備

如要使用 gdcloud 指令列介面 (CLI) 指令,請務必下載、安裝及設定 gdcloud CLI。Distributed Cloud 的所有指令都使用 gdcloud 或 kubectl CLI,且需要作業系統 (OS) 環境。

取得 kubeconfig 檔案路徑

如要對 Management API 伺服器執行指令,請確認您具備下列資源:

  1. 如果您沒有 Management API 伺服器的 kubeconfig 檔案,請登入並產生該檔案。

  2. 請使用 Management API 伺服器的 kubeconfig 檔案路徑,取代這些操作說明中的 MANAGEMENT_API_SERVER。

要求 IAM 角色

請與 IAM 專案管理員聯絡,要求在專案中取得下列角色:

  • 虛擬機器專案管理員 (project-vm-admin):建立、修改、列出及刪除專案命名空間中的 VM。

  • 專案檢視者(project-viewer):查看專案命名空間中的所有資源。

所有 VM 角色都必須繫結至 VM 所在專案的命名空間。按照步驟驗證存取權。

可更新的屬性

您只能變更 VM spec 中的屬性。

查看可更新的屬性

使用 GDC 控制台或 kubectl 找出要變更的屬性。

控制台

  1. 在導覽選單中,依序點選「虛擬機器」>「執行個體」。

  2. 在 VM 清單中,按一下 VM 名稱即可查看其屬性。

  3. 可編輯的屬性會顯示「編輯」圖示 。

kubectl

  1. 查看 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.
    
       ...
    
  2. 遞迴查看每個屬性的子屬性。以下範例顯示 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,變更才會生效:

這些屬性更新會立即生效:

  • guestEnvironment
  • runningState

更新 VM 屬性

使用 GDC 控制台或 kubectl 更新 VM 屬性。

控制台

  1. 在導覽選單中,依序點選「虛擬機器」>「執行個體」。

  2. 在 VM 清單中,按一下 VM 名稱即可查看其屬性。

  3. 按一下要編輯的屬性旁邊的「 編輯」,然後進行變更。

  4. 如要更換開機磁碟或新增磁碟,請參閱「更換開機磁碟」或「將磁碟新增至 VM」。

  5. 按一下 [儲存]。

kubectl

  1. 執行下列指令:

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

    請替換下表定義的變數。

    變數定義
    MANAGEMENT_API_SERVERManagement API 伺服器 kubeconfig 檔案。
    VM_NAMEVM 的名稱。
    PROJECT專案名稱。
  2. 編輯 spec,更新可更新屬性的必要欄位和值。

  3. 儲存檔案。

  4. 如果更新屬性後需要重新啟動 VM,請按照「重新啟動 VM」的操作說明重新啟動 VM。