管理巢狀虛擬化限制


本文說明如何檢查是否已啟用巢狀虛擬化,以及如何修改布林限制,控制機構、專案或資料夾是否啟用巢狀虛擬化。

機構政策中的布林值限制會決定您是否可以建立巢狀 VM。巢狀虛擬化的布林限制是項限制,也就是說,強制執行這項限制時,系統會告知機構政策禁止建立巢狀 VM。如要進一步瞭解布林限制,請參閱「瞭解限制」。

「停用 VM 巢狀虛擬化」限制預設不會強制執行,因此您不必修改任何布林限制,即可啟用巢狀虛擬化。儘管如此,Google 仍建議您明確設定限制的值,以免貴機構、資料夾和專案依賴預設設定。如果專案不屬於機構,系統預設不會強制執行限制,您也無法變更限制。

事前準備

  • 如果尚未設定驗證,請先完成設定。 「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

      1. After installing the Google Cloud CLI, initialize it by running the following command:

        gcloud init

        If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      2. Set a default region and zone.
      3. REST

        如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

          After installing the Google Cloud CLI, initialize it by running the following command:

          gcloud init

          If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。

檢查是否允許巢狀虛擬化

使用 Google Cloud 控制台、Google Cloud CLI 或 REST,檢查機構、資料夾或專案是否允許巢狀虛擬化。

主控台

如要確認是否可以在機構、資料夾或專案中建立巢狀 VM,請檢查是否未強制執行停用巢狀虛擬化的布林值限制。如果機構政策未強制執行「停用 VM 巢狀虛擬化」限制,您就可以建立巢狀 VM。

  1. 前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。

    前往「機構政策」

  2. 在機構、資料夾和專案選取器中,選取要查看機構政策的實體。

  3. 選取「Disable VM nested virtualization」(停用 VM 巢狀虛擬化) 限制,開啟「Policy details」(政策詳細資料) 頁面。

  4. 查看「強制執行」的值:

    • 如果值為「Not enforced」(未強制執行),則會啟用巢狀虛擬化,您可以建立巢狀 VM。

    • 如果值為「強制執行」,則巢狀虛擬化功能會停用,您無法建立巢狀 VM。

gcloud

使用 gcloud resource-manager org-policies describe 指令,檢查 compute.disableNestedVirtualization 布林值限制的值。

如果 Google Cloud CLI 輸出內容未顯示 booleanPolicy 的值,表示允許巢狀虛擬化,您可以建立巢狀 VM。

如果 Google Cloud CLI 輸出值為 booleanPolicy,則表示機構政策強制執行停用巢狀虛擬化限制,因此您無法建立巢狀 VM。booleanPolicyenforced: true

gcloud resource-manager org-policies \
  describe constraints/compute.disableNestedVirtualization \
  (--organization=ORGANIZATION_ID | --folder=FOLDER_ID |
  --project=PROJECT_ID) --effective

請替換下列其中一項:

REST

使用 REST 檢查 compute.disableNestedVirtualization 布林限制的值,判斷您是否可以在機構、資料夾或專案中建立巢狀 VM。

如果 REST 回應未傳回限制的 "booleanPolicy" 值,則巢狀虛擬化不會停用,您可以建立巢狀 VM。

如果輸出內容中 "booleanPolicy" 的值為 "enforced": true,表示巢狀虛擬化已停用,您無法建立巢狀 VM。

POST https://cloudresourcemanager.googleapis.com/v1/RESOURCE/RESOURCE_ID:getOrgPolicy

{
  "constraint": "compute.disableNestedVirtualization"
}

更改下列內容:

修改巢狀虛擬化組織政策

如果您具備適當的角色,可以控管機構、資料夾或專案是否能建立巢狀 VM。如要控管這項強制執行作業,請使用巢狀虛擬化的布林限制。

使用 Google Cloud 控制台、Google Cloud CLI 或 REST,為機構、資料夾或專案啟用巢狀虛擬化。

主控台

如要啟用巢狀虛擬化功能,請停用「停用 VM 巢狀虛擬化功能」布林限制的強制執行功能;如要停用巢狀虛擬化功能,請啟用布林限制的強制執行功能。

  1. 前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。

    前往「機構政策」

  2. 在機構、資料夾和專案選取器中,選取要編輯機構政策的實體。

  3. 選取「Disable VM nested virtualization」(停用 VM 巢狀虛擬化) 限制,開啟「Policy details」(政策詳細資料) 頁面。

  4. 按一下「編輯」,然後選取「自訂」

  5. 在「Enforcement」(強制執行) 下方,為「Disable VM nested virtualization」(停用 VM 巢狀虛擬化功能) 布林限制選取下列任一強制執行選項:

    • 開啟:啟用強制執行設定並停用巢狀虛擬化
    • 關閉:停用強制執行設定,並啟用巢狀虛擬化功能
  6. 按一下 [儲存]

gcloud

使用 gcloud resource-manager org-policies 指令啟用或停用 compute.disableNestedVirtualization 機構政策布林限制的強制執行功能。

如果您使用 disable-enforce 指令停用 compute.disableNestedVirtualization 限制,即可建立啟用巢狀虛擬化的 VM。

如果您使用 enable-enforce 指令啟用限制,就無法建立已啟用巢狀虛擬化的 VM。

gcloud resource-manager org-policies \
  ( disable-enforce | enable-enforce ) compute.disableNestedVirtualization \
  (--organization=ORGANIZATION_ID | --folder=FOLDER_ID |
  --project=PROJECT_ID)

請替換下列其中一項:

REST

使用 REST 修改 compute.disableNestedVirtualization 布林限制的值,決定是否能在機構、資料夾或專案中建立巢狀 VM。

POST https://cloudresourcemanager.googleapis.com/v1/RESOURCE/RESOURCE_ID:setOrgPolicy

{
  "policy": {
    "booleanPolicy": {
      "enforced": ENFORCE
    },
    "constraint": "constraints/compute.disableNestedVirtualization"
  }
}

更改下列內容:

  • RESOURCE:要修改機構政策的資源。請將此值設為下列其中一項:

  • RESOURCE_ID:要檢查停用巢狀虛擬化限制狀態的機構、資料夾或專案

  • ENFORCE:決定組織政策是否強制執行 compute.disableNestedVirtualization 布林值限制。請設為下列其中一個值:

    • true:強制執行限制。啟用這項設定後,您就無法建立啟用巢狀虛擬化的 VM。

    • false:不強制執行限制。啟用這項設定後,您就能建立啟用巢狀虛擬化的 VM。

後續步驟