kube-proxy 會設定節點的 iptables 規則,將流量分配到多個 Pod。要是沒有容器原生負載平衡,負載平衡器流量會前往節點執行個體群組,並且透過 iptables 規則轉送到多個 Pod,而這些 Pod 不一定位於同一節點內。要是擁有容器原生負載平衡,負載平衡器流量會直接分配到多個 Pod,而這些 Pod 應接收流量,並且消除額外的網路躍點。此外,容器原生負載平衡直接以 Pod 為目標,因此健康狀態檢查可獲得改善。
比較預設行為 (左) 和容器原生負載平衡器行為。
網路效能獲得改善
因為容器原生負載平衡器可直接與 Pod 交流,而且連線的網路躍點較少,所以延遲時間和總處理量都獲得改善。
瀏覽權限提升
使用容器原生負載平衡時,您有權限可瀏覽應用程式負載平衡器到 Pod 的延遲。您可以看到從應用程式負載平衡器到每個 Pod 的延遲時間,這些時間是透過節點 IP 型容器原生負載平衡匯總而來。如此一來,NEG 層級服務的疑難排解就會變得更加容易。
對於相關的 Pod,相應的 Ingress 控制器會管理 cloud.google.com/load-balancer-neg-ready 類型的完備性門檻。Ingress 控制器會輪詢負載平衡器的健康狀態檢查狀態,包括 NEG 中所有端點的健康狀態。當負載平衡器健康狀態檢查的狀態,顯示出與特定 Pod 對應的端點處於健康狀態時,Ingress 控制器會將 Pod 的完備性門檻值設為 True。然後,在每個節點上執行的 kubelet 會將完備性門檻的值以及 Pod 的完備性探測 (如有定義) 一併納入考量,計算 Pod 的有效完備性。
透過 Ingress 使用容器原生負載平衡時,系統會自動啟用 Pod 完備性門檻。
完備性門檻會控制滾動式更新的速率。當您啟動滾動式更新時,隨著 GKE 建立新的 Pod,會將每個新 Pod 的端點新增至 NEG。從負載平衡器的角度來看,當端點處於健康狀態時,Ingress 控制器會將完備性門檻設為 True。新建立的 Pod 必須至少通過其完備性門檻,「接下來」GKE 才能刪除舊的 Pod。這樣可確保 Pod 的對應端點已通過負載平衡器的健康狀態檢查,並確保後端容量維持不變。
如果 Pod 的完備性門檻並未顯示 Pod 已準備就緒,可能是因為容器映像檔錯誤,或是負載平衡器健康狀態檢查設定錯誤,導致負載平衡器未將流量導向新 Pod。如果在推出更新後的 Deployment 時發生故障,在嘗試建立新的 Pod 後,因為該 Pod 的完備性門檻永遠不會為 True,所以會暫停推出。如要瞭解如何偵測並修正這種狀況,請參閱疑難排解一節。
在缺少容器原生負載平衡和完備性門檻的情況下,GKE 在將 Pod 標記為準備就緒之前,無法偵測到負載平衡器的端點是否處於健康狀態。在先前的 Kubernetes 版本中,您可以指定延遲期間 (Deployment 規格中的 minReadySeconds) 來控制 Pod 移除和替換的速率。
如果符合下列任一條件,GKE 會將 Pod 的 cloud.google.com/load-balancer-neg-ready 值設為 True:
[[["容易理解","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,["# Container-native load balancing\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page explains container-native load balancing in\nGoogle Kubernetes Engine (GKE).\n\nThis page assumes that you know about\n[Cloud Load Balancing](/load-balancing/docs/load-balancing-overview#load-balancer-types)\nand\n[zonal network endpoint groups (NEGs)](/load-balancing/docs/negs/zonal-neg-concepts).\nWith container-native load balancing, these load balancers can directly and\nand evenly distribute traffic to Pods.\n\nContainer-native load balancing architecture\n--------------------------------------------\n\nContainer-native load balancing uses\n[`GCE_VM_IP_PORT` network endpoint groups (NEGs)](/load-balancing/docs/negs/zonal-neg-concepts#gce-vm-ip-port).\nThe endpoints of the NEG are Pod IP addresses.\n\nContainer-native load balancing is always used for internal GKE\nIngress and is optional for external Ingress. The Ingress controller creates the\nload balancer, including the virtual IP address, forwarding rules, health\nchecks, and firewall rules.\n\nTo learn how to use container-native load balancing with Ingress, see\n[Container-native load balancing through Ingress](/kubernetes-engine/docs/how-to/container-native-load-balancing).\n\nFor more flexibility, you can also\n[create standalone NEGs](/kubernetes-engine/docs/how-to/standalone-neg). In this\ncase, you are responsible for creating and managing all aspects of the load\nbalancer.\n\nBenefits of container-native load balancing\n-------------------------------------------\n\nContainer-native load balancing offers the following benefits:\n\nPods are core objects for load balancing\n: [kube-proxy](https://kubernetes.io/docs/reference/command-line-tools-reference/kube-proxy/)\n configures nodes' `iptables` rules to distribute traffic to Pods. Without\n container-native load balancing, load balancer\n traffic travels to the node instance groups and gets routed using `iptables`\n rules to Pods which might or might not be in the same node. With\n container-native load balancing, load balancer traffic is distributed directly\n to the Pods which should receive the traffic, eliminating the extra network\n hop. Container-native load balancing also helps with improved health checking\n since it targets Pods directly. \n\n\n Comparison of default behavior (left) with container-native load balancer behavior.\n\nImproved network performance\n: Because the container-native load balancer talks directly with the Pods, and\n connections have fewer network hops, both latency and throughput are improved.\n\nIncreased visibility\n: With container-native load balancing, you have visibility into the latency\n from the Application Load Balancer to Pods. The latency from the\n Application Load Balancer to each Pod is visible, which were aggregated with\n node IP-base container-native load balancing. This makes troubleshooting your\n Services at the NEG-level easier.\n\nSupport for advanced load balancing features\n: Container-native load balancing in GKE supports several\n features of external Application Load Balancers, such as integration with Google Cloud services\n like\n [Google Cloud Armor](/kubernetes-engine/docs/how-to/cloud-armor-backendconfig),\n [Cloud CDN](/kubernetes-engine/docs/how-to/cdn-backendconfig), and\n [Identity-Aware Proxy](/iap/docs/enabling-kubernetes-howto). It also features load\n balancing algorithms for accurate traffic distribution.\n\nSupport for Cloud Service Mesh\n: The NEG data model is required to use [Cloud Service Mesh](/traffic-director/docs),\n Google Cloud's fully managed traffic control plane for service mesh.\n\nPod readiness\n-------------\n\nFor relevant Pods, the corresponding Ingress controller manages a\n[readiness gate](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-readiness-gate)\nof type `cloud.google.com/load-balancer-neg-ready`. The Ingress controller polls\nthe load balancer's\n[health check status](/load-balancing/docs/health-check-concepts), which\nincludes the health of all endpoints in the NEG. When the load balancer's health\ncheck status indicates that the endpoint corresponding to a particular Pod is\nhealthy, the Ingress controller sets the Pod's readiness gate value to `True`.\nThe kubelet running on each Node then computes the Pod's effective readiness,\nconsidering both the value of this readiness gate and, if defined, the Pod's\n[readiness probe](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-readiness-probes).\n\nPod readiness gates are automatically enabled when using container-native\nload balancing through Ingress.\n\nReadiness gates control the rate of a rolling update. When you initiate a\nrolling update, as GKE creates new Pods, an endpoint for each new\nPod is added to a NEG. When the endpoint is healthy from the perspective of the\nload balancer, the Ingress controller sets the readiness gate to `True`. A\nnewly created Pod must at least pass its readiness gate *before*\nGKE removes an old Pod. This ensures that the corresponding\nendpoint for the Pod has already passed the load balancer's health check and\nthat the backend capacity is maintained.\n\nIf a Pod's readiness gate never indicates that the Pod is ready, due to a bad\ncontainer image or a misconfigured load balancer health check, the load balancer\nwon't direct traffic to the new Pod. If such a failure occurs while rolling out\nan updated Deployment, the rollout stalls after attempting to create one new\nPod because that Pod's readiness gate is never True. See the\n[troubleshooting section](/kubernetes-engine/docs/how-to/container-native-load-balancing#stalled_rollout)\nfor information on how to detect and fix this situation.\n\nWithout container-native load balancing and readiness gates, GKE\ncan't detect if a load balancer's endpoints are healthy before marking Pods as\nready. In previous Kubernetes versions, you control the\nrate that Pods are removed and replaced by specifying a delay period\n(`minReadySeconds` in the Deployment specification).\n\nGKE sets the value of\n`cloud.google.com/load-balancer-neg-ready` for a Pod to `True` if any of the\nfollowing conditions are met:\n\n- None of the Pod's IP addresses are endpoints in a [`GCE_VM_IP_PORT` NEG](/load-balancing/docs/negs) managed by the GKE control plane.\n- One or more of the Pod's IP addresses are endpoints in a `GCE_VM_IP_PORT` NEG managed by the GKE control plane. The NEG is attached to a [backend service](/load-balancing/docs/backend-service). The backend service has a successful load balancer health check.\n- One or more of the Pod's IP addresses are endpoints in a `GCE_VM_IP_PORT` NEG managed by the GKE control plane. The NEG is attached to a backend service. The load balancer health check for the backend service [times out](/load-balancing/docs/health-check-concepts#method).\n- One or more of the Pod's IP addresses are endpoints in one or more `GCE_VM_IP_PORT` NEGs. None of the NEGs are attached to a backend service. No load balancer health check data is available.\n\nSession affinity\n----------------\n\nContainer-native load balancing supports\nPod-based\n[session affinity](/load-balancing/docs/backend-service#session_affinity).\n\nRequirements for using container-native load balancing\n------------------------------------------------------\n\nContainer-native load balancers through Ingress on GKE have the\nfollowing requirements:\n\n- The cluster must be VPC-native.\n- The cluster must have the `HttpLoadBalancing` add-on enabled. GKE clusters have the `HttpLoadBalancing` add-on enabled by default; you must not disable it.\n\nLimitations for container-native load balancers\n-----------------------------------------------\n\nContainer-native load balancers through Ingress on GKE have the\nfollowing limitations:\n\n- Don't support external passthrough Network Load Balancers.\n- You must not manually change or update the configuration of the Application Load Balancer that GKE creates. Any changes that you make are overwritten by GKE.\n\nPricing for container-native load balancers\n-------------------------------------------\n\nYou are charged for the Application Load Balancer provisioned by the Ingress that\nyou create in this guide. For load balancer pricing information, refer to\n[Load balancing and forwarding rules](/vpc/network-pricing#lb) on the\nVPC pricing page.\n\nWhat's next\n-----------\n\n- Learn more about [NEGs](/load-balancing/docs/negs).\n- Learn more about [VPC-native clusters](/kubernetes-engine/docs/how-to/alias-ips).\n- Learn more about [external Application Load Balancers](/load-balancing/docs).\n- Watch a [KubeCon talk about Pod readiness gates](https://www.youtube.com/watch?v=Vw9GmSeomFg)."]]