本頁說明如何在 Google Kubernetes Engine (GKE) 中使用 StatefulSet 物件。您也可以瞭解如何部署有狀態應用程式。
關於 StatefulSet
StatefulSet 代表一組具有不重複永久身分和穩定主機名稱的 Pod,無論排定在何處,GKE 都會維護這些 Pod。任何 StatefulSet Pod 的狀態資訊和其他彈性資料,都會保留在與 StatefulSet 中每個 Pod 相關聯的持續性磁碟區中。StatefulSet Pod 隨時可以重新啟動。
確認 Service 中的 `metadata.name` 與 StatefulSet 中的 serviceName 欄位相符。這可讓應用程式中的每個 Pod 都能以明確定義的專屬網路位址存取。此外,無介面服務會為 StatefulSet 中的每個副本提供多個 IP 記錄,方便進行完整的對等互連探索。
同類應用程式探索
有狀態應用程式需要最少數量的副本 (仲裁) 才能正常運作,並維持完整可用性。
由於 Pod 可能會當機、重新排程或遭到撤銷,StatefulSet 中的每個副本都應能離開並重新加入仲裁。需要對等互連的應用程式應具備透過 Kubernetes 中無標題服務探索其他對等互連的功能。
[[["容易理解","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,["# About StatefulSets in GKE\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page describes the use of *StatefulSet* objects in\nGoogle Kubernetes Engine (GKE). You can also learn how to\n[Deploy a stateful application](/kubernetes-engine/docs/how-to/stateful-apps).\n\nAbout StatefulSets\n------------------\n\nStatefulSets represent a set of Pods with unique, persistent identities, and\nstable hostnames that GKE maintains regardless of where they are\nscheduled. The state information and other resilient data for any given\nStatefulSet Pod is maintained in [persistent\nvolumes](/kubernetes-engine/docs/concepts/persistent-volumes) associated with\neach Pod in the StatefulSet. StatefulSet Pods can be restarted at any time.\n\nFor [stateless applications](/kubernetes-engine/docs/how-to/deploying-workloads-overview#stateless_applications), use\n[Deployments](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/).\n\nStatefulSets function similarly in GKE and in Kubernetes. This\ndocument describes any GKE-specific considerations. To learn\nhow StatefulSets work, see the\n[Kubernetes documentation about StatefulSets](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/).\n\n### Plan networking for StatefulSets\n\nStatefulSets provide persistent storage in the form of a PersistentVolume and a\nunique network identity (hostname). The following table includes the caveats that\napplication operators should be aware of when configuring a StatefulSet:\n\nTo read more about probes, see [Configure Liveness, Readiness, and Startup Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes).\n\n\nWork with StatefulSets\n----------------------\n\nTo learn how to deploy StatefulSets in your GKE cluster and\ninteract with them, see the Kubernetes documentation about\n[StatefulSet basics](https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/).\n\nWhat's next\n-----------\n\n- [Learn how to deploy a stateful application](/kubernetes-engine/docs/how-to/stateful-apps)\n- [Learn how to update StatefulSets using rolling updates](https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#rolling-update)\n- [Learn more about deploying workloads in GKE](/kubernetes-engine/docs/how-to/deploying-workloads-overview)\n- [Read more about StatefulSets in the Kubernetes documentation](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/)\n- [Take a tutorial about upgrading a cluster running a stateful workload](/kubernetes-engine/docs/tutorials/upgrading-stateful-workload)"]]