下頁說明如何建立 Google Kubernetes Engine (GKE) 標準叢集,並使用支援巢狀虛擬化的節點。Compute Engine VM 使用 Intel VT-x 指令,因此巢狀 VM 可以在 GKE 節點的基礎 VM 上執行。然後,您可以使用 QEMU 等工具部署 Pod,建立巢狀 VM。您可以使用巢狀 VM 執行專門工作負載,例如 Android 模擬器,或是可將 VM 做為隔離界線的工作負載。
減少效能影響
使用硬體輔助巢狀虛擬化時,與非巢狀虛擬化設定相比,在巢狀 VM 上執行的工作負載效能可能會降低。效能影響程度取決於特定工作負載設定檔,包括其 I/O 和記憶體用量特性。
此外,在 GKE 節點的基礎 VM 上建立巢狀 VM,可能會影響在這些節點上執行的其他工作負載效能。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-01 (世界標準時間)。"],[],[],null,["# Use nested VMs with GKE Standard clusters\n\n[Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThe following page explains how you can create Google Kubernetes Engine (GKE)\nStandard clusters with nodes that support [nested\nvirtualization](/compute/docs/instances/nested-virtualization/overview#restrictions).\nCompute Engine VMs use [Intel\nVT-x](https://www.intel.com/content/dam/www/central-libraries/us/en/documents/intel-virtualization-technologies-white-paper.pdf)\ninstructions so that nested VMs can run on a [GKE node's\nunderlying VM](/kubernetes-engine/docs/concepts/cluster-architecture#nodes).\nThen, you can deploy Pods that use tools such as [QEMU](https://www.qemu.org/)\nto create nested VMs. You can use nested VMs to run specialized workloads such\nas Android emulators, or workloads that benefit from the VM as an isolation\nboundary.\n\nReduced performance implications\n--------------------------------\n\nWith hardware-assisted nested virtualization, workloads running on the nested\nVMs might experience [reduced\nperformance](/compute/docs/instances/nested-virtualization/overview#performance_considerations)\nwhen compared to non-nested virtualization configurations. The amount of\nperformance impact will depend on the specific workload profile, including its\nI/O and memory usage characteristics.\n\nAdditionally, creating nested VMs on the GKE nodes' underlying\nVMs might affect the performance of other workloads running on those nodes.\n\nBefore you begin\n----------------\n\nBefore you start, make sure that you have performed the following tasks:\n\n- Enable the Google Kubernetes Engine API.\n[Enable Google Kubernetes Engine API](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com)\n- If you want to use the Google Cloud CLI for this task, [install](/sdk/docs/install) and then [initialize](/sdk/docs/initializing) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running `gcloud components update`. **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](/sdk/docs/properties#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.\n\n\u003c!-- --\u003e\n\n- [Ensure that your organization policy supports creating nested VMs](/compute/docs/instances/nested-virtualization/managing-constraint#check_whether_nested_virtualization_is_allowed).\n- Review the nested VM [restrictions](/compute/docs/instances/nested-virtualization/overview#restrictions).\n\n### Requirements and limitations\n\nConsider the following information before enabling nested virtualization with\nGKE and allowing your Pods to create nested VMs:\n\n- You can only configure node pools with nested VMs with a limited number of VM machine series. See the **Nested virtualization** row of the [Machine\n series comparison](/compute/docs/machine-resource#machine_type_comparison) to confirm supported machine series.\n- You must use the `UBUNTU_CONTAINERD` image type, or the `COS_CONTAINERD`image type with nodes running version 1.28.4-gke.1083000 or later.\n- You can only use nested virtualization with Standard clusters, not Autopilot clusters.\n- You can't use [node\n auto-provisioning](/kubernetes-engine/docs/concepts/node-auto-provisioning) with nested virtualization-enabled node pools.\n- You can't use nested virtualization if the [*Disable VM nested virtualization*\n constraint](/compute/docs/instances/nested-virtualization/managing-constraint#console) is enforced for your organization policy.\n- You must set `securityContext.privileged:true` for Pods to interact with nested VMs.\n\nEnable nested virtualization\n----------------------------\n\nYou can enable nested virtualization when you create a cluster---by enabling it\nfor the default node pool---or when you create a node pool. You can't enable or\ndisable the feature for an existing node pool.\n\nThe instructions in the following sections create node pools with nodes with the\nlabel `nested-virtualization=enabled`. After GKE creates the\nnodes, you can schedule Pods that created nested VMs on the node's underlying\nVM.\n\n### Enable nested virtualization with a new Standard cluster\n\nCreate a new Standard cluster with nested virtualization enabled for\nthe default node pool. GKE only creates the default node pool\nwith nested virtualization enabled. GKE doesn't automatically\nenable the feature for all new node pools created for the cluster: \n\n gcloud container clusters create \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e \\\n --enable-nested-virtualization \\\n --node-labels=nested-virtualization=enabled \\\n --machine-type=\u003cvar translate=\"no\"\u003eMACHINE_TYPE\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: The name of the cluster.\n- \u003cvar translate=\"no\"\u003eMACHINE_TYPE\u003c/var\u003e: A [supported machine type (see the\n **Nested virtualization row**)](/compute/docs/machine-resource#machine_type_comparison).\n\nOptionally, [check that nested virtualization is\nenabled](/compute/docs/instances/nested-virtualization/enabling#confirm_that_nested_virtualization_is_enabled_on_the_vm)\nfor a node in the node pool.\n\nYou can now [schedule Pods](#schedule-pod) that create nested VMs on the\nunderlying VM of the node.\n\n### Enable nested virtualization with a new node pool\n\nCreate a new node pool with nested virtualization enabled for an existing\nStandard cluster: \n\n gcloud container node-pools create \u003cvar translate=\"no\"\u003eNODEPOOL_NAME\u003c/var\u003e \\\n --enable-nested-virtualization \\\n --node-labels=nested-virtualization=enabled \\\n --cluster=\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e \\\n --machine-type=\u003cvar translate=\"no\"\u003eMACHINE_TYPE\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eNODEPOOL_NAME\u003c/var\u003e: The name of the node pool where nested virtualization is enabled.\n- \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: The name of the cluster.\n- \u003cvar translate=\"no\"\u003eMACHINE_TYPE\u003c/var\u003e: A [support machine type (see the\n **Nested virtualization row**)](/compute/docs/machine-resource#machine_type_comparison).\n\nOptionally, [check that nested virtualization is\nenabled](/compute/docs/instances/nested-virtualization/enabling#confirm_that_nested_virtualization_is_enabled_on_the_vm)\nfor a node in the node pool.\n\nYou can now [schedule Pods](#schedule-pod) that create nested VMs on the\nunderlying VM of the node.\n\nSchedule a Pod to a node that supports nested virtualization\n------------------------------------------------------------\n\nTo schedule a Pod on a node with nested virtualization enabled, add the\nfollowing node selector to the specification: \n\n nodeSelector:\n nested-virtualization: enabled\n\nAdditionally, for the Pod to connect with a nested VM, you must set the Pod as\nprivileged by configuring `securityContext.privileged:true`.\n\nWhat's next\n-----------\n\n- [About nested virtualization](/compute/docs/instances/nested-virtualization/overview)"]]