Kubernetes API 健康端点

Kubernetes API 服务器 提供 API 端点以指示 API 服务器的当前状态。 本文描述了这些 API 端点,并说明如何使用。

API 健康端点

Kubernetes API 服务器提供 3 个 API 端点(healthzlivezreadyz)来表明 API 服务器的当前状态。 healthz 端点已被弃用(自 Kubernetes v1.16 起),你应该使用更为明确的 livezreadyz 端点。 livez 端点可与 --livez-grace-period 标志一起使用,来指定启动持续时间。 为了正常关机,你可以使用 /readyz 端点并指定 --shutdown-delay-duration 标志。 检查 API 服务器的 health/livez/readyz 端点的机器应依赖于 HTTP 状态代码。 状态码 200 表示 API 服务器是 healthylive 还是 ready,具体取决于所调用的端点。 以下更详细的选项供操作人员使用,用来调试其集群或专门调试 API 服务器的状态。

以下示例将显示如何与运行状况 API 端点进行交互。

对于所有端点,都可以使用 verbose 参数来打印检查项以及检查状态。 这对于操作人员调试 API 服务器的当前状态很有用,这些不打算给机器使用:

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

或从具有身份验证的远程主机:

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

输出将如下所示:

  1. [+]ping ok
  2. [+]log ok
  3. [+]etcd ok
  4. [+]poststarthook/start-kube-apiserver-admission-initializer ok
  5. [+]poststarthook/generic-apiserver-start-informers ok
  6. [+]poststarthook/start-apiextensions-informers ok
  7. [+]poststarthook/start-apiextensions-controllers ok
  8. [+]poststarthook/crd-informer-synced ok
  9. [+]poststarthook/bootstrap-controller ok
  10. [+]poststarthook/rbac/bootstrap-roles ok
  11. [+]poststarthook/scheduling/bootstrap-system-priority-classes ok
  12. [+]poststarthook/start-cluster-authentication-info-controller ok
  13. [+]poststarthook/start-kube-aggregator-informers ok
  14. [+]poststarthook/apiservice-registration-controller ok
  15. [+]poststarthook/apiservice-status-available-controller ok
  16. [+]poststarthook/kube-apiserver-autoregistration ok
  17. [+]autoregister-completion ok
  18. [+]poststarthook/apiservice-openapi-controller ok
  19. healthz check passed

Kubernetes API 服务器也支持排除特定的检查项。 查询参数也可以像以下示例一样进行组合:

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

输出显示排除了 etcd 检查:

  1. [+]ping ok
  2. [+]log ok
  3. [+]etcd excluded: ok
  4. [+]poststarthook/start-kube-apiserver-admission-initializer ok
  5. [+]poststarthook/generic-apiserver-start-informers ok
  6. [+]poststarthook/start-apiextensions-informers ok
  7. [+]poststarthook/start-apiextensions-controllers ok
  8. [+]poststarthook/crd-informer-synced ok
  9. [+]poststarthook/bootstrap-controller ok
  10. [+]poststarthook/rbac/bootstrap-roles ok
  11. [+]poststarthook/scheduling/bootstrap-system-priority-classes ok
  12. [+]poststarthook/start-cluster-authentication-info-controller ok
  13. [+]poststarthook/start-kube-aggregator-informers ok
  14. [+]poststarthook/apiservice-registration-controller ok
  15. [+]poststarthook/apiservice-status-available-controller ok
  16. [+]poststarthook/kube-apiserver-autoregistration ok
  17. [+]autoregister-completion ok
  18. [+]poststarthook/apiservice-openapi-controller ok
  19. [+]shutdown ok
  20. healthz check passed

独立健康检查

FEATURE STATE: Kubernetes v1.21 [alpha]

每个单独的健康检查都会公开一个 http 端点,并且可以单独检查。 单个运行状况检查的模式为 /livez/<healthcheck-name>,其中 livezreadyz 表明你要检查的是 API 服务器是否存活或就绪。 <healthcheck-name> 的路径可以通过上面的 verbose 参数发现 ,并采用 [+]ok 之间的路径。 这些单独的健康检查不应由机器使用,但对于操作人员调试系统而言,是有帮助的:

  1. curl -k https://localhost:6443/livez/etcd