更新 VM 屬性

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

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

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

本文適用於平台管理員或應用程式運算子群組的開發人員,他們會在 Distributed Cloud 環境中查看及更新 VM 屬性。詳情請參閱 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):在專案命名空間中建立、修改、列出及刪除 VM。

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

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

可更新的屬性

您只能變更 VM 的 spec 屬性。

查看可更新的屬性

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

控制台

  1. 在導覽選單中,依序點選「Virtual Machines」>「Instances」(虛擬機器 > 執行個體)

  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. 遞迴查看每個屬性的子屬性。以下範例顯示 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.
      

您可以在執行中的 VM 上更新所有屬性,但通常需要重新啟動 VM 才會生效。

更新這些屬性後,必須重新啟動 VM,變更才會生效:

下列屬性更新會立即生效:

  • guestEnvironment
  • runningState

更新 VM 屬性

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

控制台

  1. 在導覽選單中,依序點選「Virtual Machines」>「Instances」(虛擬機器 > 執行個體)

  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」一節的說明操作。