Kubernetes API 健康端點

Kubernetes API 伺服器 提供 API 端點來指示 API 伺服器的目前狀態。本頁面說明這些 API 端點,並解釋如何使用它們。

健康狀態的 API 端點

Kubernetes API 伺服器提供 3 個 API 端點 (healthzlivezreadyz) 來指示 API 伺服器的目前狀態。healthz 端點已棄用 (自 Kubernetes v1.16 起),您應該改用更具體的 livezreadyz 端點。livez 端點可以搭配 --livez-grace-period flag 使用,以指定啟動持續時間。對於優雅關閉,您可以搭配 /readyz 端點指定 --shutdown-delay-duration flag。檢查 API 伺服器的 healthz/livez/readyz 的機器應依賴 HTTP 狀態碼。狀態碼 200 表示 API 伺服器處於 健康/運作中/就緒 狀態,具體取決於呼叫的端點。以下顯示的更詳細選項旨在供人工操作員用於偵錯其叢集或了解 API 伺服器的狀態。

以下範例將示範如何與健康狀態 API 端點互動。

對於所有端點,您可以使用 verbose 參數來印出檢查及其狀態。這對於人工操作員偵錯 API 伺服器的目前狀態可能很有用,但不適合由機器使用

curl -k https://localhost:6443/livez?verbose

或從具有身份驗證的遠端主機

kubectl get --raw='/readyz?verbose'

輸出看起來會像這樣

[+]ping ok
[+]log ok
[+]etcd ok
[+]poststarthook/start-kube-apiserver-admission-initializer ok
[+]poststarthook/generic-apiserver-start-informers ok
[+]poststarthook/start-apiextensions-informers ok
[+]poststarthook/start-apiextensions-controllers ok
[+]poststarthook/crd-informer-synced ok
[+]poststarthook/bootstrap-controller ok
[+]poststarthook/rbac/bootstrap-roles ok
[+]poststarthook/scheduling/bootstrap-system-priority-classes ok
[+]poststarthook/start-cluster-authentication-info-controller ok
[+]poststarthook/start-kube-aggregator-informers ok
[+]poststarthook/apiservice-registration-controller ok
[+]poststarthook/apiservice-status-available-controller ok
[+]poststarthook/kube-apiserver-autoregistration ok
[+]autoregister-completion ok
[+]poststarthook/apiservice-openapi-controller ok
healthz check passed

Kubernetes API 伺服器也支援排除特定的檢查項目。查詢參數也可以像這個範例一樣組合使用。

curl -k 'https://localhost:6443/readyz?verbose&exclude=etcd'

輸出結果顯示 etcd 檢查已被排除。

[+]ping ok
[+]log ok
[+]etcd excluded: ok
[+]poststarthook/start-kube-apiserver-admission-initializer ok
[+]poststarthook/generic-apiserver-start-informers ok
[+]poststarthook/start-apiextensions-informers ok
[+]poststarthook/start-apiextensions-controllers ok
[+]poststarthook/crd-informer-synced ok
[+]poststarthook/bootstrap-controller ok
[+]poststarthook/rbac/bootstrap-roles ok
[+]poststarthook/scheduling/bootstrap-system-priority-classes ok
[+]poststarthook/start-cluster-authentication-info-controller ok
[+]poststarthook/start-kube-aggregator-informers ok
[+]poststarthook/apiservice-registration-controller ok
[+]poststarthook/apiservice-status-available-controller ok
[+]poststarthook/kube-apiserver-autoregistration ok
[+]autoregister-completion ok
[+]poststarthook/apiservice-openapi-controller ok
[+]shutdown ok
healthz check passed

個別健康檢查

功能狀態: Kubernetes v1.32 [alpha]

每個個別的健康檢查都會公開一個 HTTP 端點,並且可以個別進行檢查。個別健康檢查的模式為 /livez/<healthcheck-name>/readyz/<healthcheck-name>,其中 livezreadyz 分別可用於指示您是否要檢查 API 伺服器的活性 (liveness) 或就緒性 (readiness)。<healthcheck-name> 路徑可以使用上述的 verbose 標記來發現,並取用 [+]ok 之間的路徑。這些個別的健康檢查不應由機器使用,但對於人工操作員來說,在偵錯系統時可能會有所幫助。

curl -k https://localhost:6443/livez/etcd
最後修改時間為 2023 年 12 月 21 日下午 4:58 PST:[en] 修正健康檢查文件的 schema 註解 (73ede84c98)