大网数据广告活动
Kubernetes 部署与运维

Kubernetes z-pages

· 52CE 我爱测

Kubernetes 的核心组件可以暴露一系列 **z-endpoints**,以便用户更轻松地调试他们的集群及其组件。 这些端点仅用于人工检查,以获取组件二进制文件的实时调试信息。 在 Kubernetes 中,这些是 **Beta** 特性。

Kubernetes 的核心组件可以暴露一系列 z-endpoints,以便用户更轻松地调试他们的集群及其组件。 这些端点仅用于人工检查,以获取组件二进制文件的实时调试信息。 在 Kubernetes 中,这些是 Beta 特性。

z-pages

Kubernetes v 允许你启用 z-pages 来帮助排查其核心控制平面组件的问题。 这些特殊的调试端点提供与正在运行的组件有关的内部信息。 对于 Kubernetes , 这些组件提供以下端点(当启用 z-pages 后):

statusz

使用 ComponentStatusz 特性门控启用后, /statusz 端点显示有关组件的高级信息,例如其 Kubernetes 版本、仿真版本、启动时间等。

来自 API 服务器的 /statusz 纯文本响应类似于:

kube-apiserver statusz
Warning: This endpoint is not meant to be machine parseable, has no formatting compatibility guarantees and is for debugging purposes only.

Started: Wed Oct 16 21:03:43 UTC 2024
Up: 0 hr 00 min 16 sec
Go version: go1.23.2
Binary version: 1.32.0-alpha.0.1484+5eeac4f21a491b-dirty
Emulation version: 1.32.0-alpha.0.1484
Paths: /healthz /livez /metrics /readyz /statusz /version

statusz(结构化的) {#statusz-structured}

从 Kubernetes v1.35 开始,/statusz 端点支持结构化的、版本化的响应格式, 前提是请求时使用了正确的 Accept 标头。 如果没有 Accept 标头,则该端点默认返回纯文本响应格式。

如需获取结构化回复,请使用:

Accept: application/json;v=v1beta1;g=config.k8s.io;as=Statusz

如果你请求 application/json 时未指定所有必需参数(g、v 和 as), 服务器将响应 406 Not Acceptable。

结构化响应示例:

{
  "kind": "Statusz",
  "apiVersion": "config.k8s.io/v1beta1",
  "metadata": {
    "name": "kube-apiserver"
  },
  "startTime": "2025-10-29T00:30:01Z",
  "uptimeSeconds": 856,
  "goVersion": "go1.23.2",
  "binaryVersion": "1.35.0",
  "emulationVersion": "1.35",
  "paths": [
    "/healthz",
    "/livez",
    "/metrics",
    "/readyz",
    "/statusz",
    "/version"
  ]
}

结构化 /statusz 响应的 config.k8s.io/v1beta1 模式如下:

// Statusz is the config.k8s.io/v1beta1 schema for the /statusz endpoint.
type Statusz struct {
       // Kind is "Statusz".
       Kind string `json:"kind"`
       // APIVersion is the version of the object, e.g., "config.k8s.io/v1beta1".
       APIVersion string `json:"apiVersion"`
       // Standard object's metadata.
       // +optional
       Metadata metav1.ObjectMeta `json:"metadata,omitempty"`
       // StartTime is the time the component process was initiated.
       StartTime metav1.Time `json:"startTime"`
       // UptimeSeconds is the duration in seconds for which the component has been running continuously.
       UptimeSeconds int64 `json:"uptimeSeconds"`
       // GoVersion is the version of the Go programming language used to build the binary.
       // The format is not guaranteed to be consistent across different Go builds.
       // +optional
       GoVersion string `json:"goVersion,omitempty"`
       // BinaryVersion is the version of the component's binary.
       // The format is not guaranteed to be semantic versioning and may be an arbitrary string.
       BinaryVersion string `json:"binaryVersion"`
       // EmulationVersion is the Kubernetes API version which this component is emulating.
       // if present, formatted as "<major>.<minor>"
       // +optional
       EmulationVersion string `json:"emulationVersion,omitempty"`
       // MinimumCompatibilityVersion is the minimum Kubernetes API version with which the component is designed to work.
       // if present, formatted as "<major>.<minor>"
       // +optional
       MinimumCompatibilityVersion string `json:"minimumCompatibilityVersion,omitempty"`
       // Paths contains relative URLs to other essential read-only endpoints for debugging and troubleshooting.
       // +optional
       Paths []string `json:"paths,omitempty"`
}

flagz

使用 ComponentFlagz 特性门控启用后, /flagz 端点为你显示用于启动某组件的命令行参数。

/flagz 报告命令行标志及其默认值。 对于同时加载配置文件(如 kubelet 和 kube-proxy)的组件, 其实际运行配置可能与 /flagz 显示的内容不同; 若可用,请使用 /configz 来查看合并后的组件配置。

API 服务器的 /flagz 纯文本响应看起来类似于:

kube-apiserver flags
Warning: This endpoint is not meant to be machine parseable, has no formatting compatibility guarantees and is for debugging purposes only.

advertise-address=192.168.8.2
contention-profiling=false
enable-priority-and-fairness=true
profiling=true
authorization-mode=[Node,RBAC]
authorization-webhook-cache-authorized-ttl=5m0s
authorization-webhook-cache-unauthorized-ttl=30s
authorization-webhook-version=v1beta1
default-watch-cache-size=100

flagz(结构化的) {#flagz-structured}

从 Kubernetes v1.35 开始,/flagz 端点支持结构化、版本化的响应格式, 前提是请求时使用了正确的 Accept 标头。 如果没有 Accept 标头,则该端点默认返回纯文本响应格式。

要请求结构化响应,请使用:

Accept: application/json;v=v1alpha1;g=config.k8s.io;as=Flagz

如果你请求 application/json 时未指定所有必需参数(g、v 和 as), 服务器将响应 406 Not Acceptable。

结构化响应示例:

{
  "kind": "Flagz",
  "apiVersion": "config.k8s.io/v1beta1",
  "metadata": {
    "name": "kube-apiserver"
  },
  "flags": {
    "advertise-address": "192.168.8.4",
    "allow-privileged": "true",
    "anonymous-auth": "true",
    "authorization-mode": "[Node,RBAC]",
    "enable-priority-and-fairness": "true",
    "profiling": "true",
    "default-watch-cache-size": "100"
  }
}

结构化 /flagz 响应的 config.k8s.io/v1beta1 模式如下:

// Flagz is the config.k8s.io/v1beta1 schema for the /flagz endpoint.
type Flagz struct {
       // Kind is "Flagz".
       Kind string `json:"kind"`
       // APIVersion is the version of the object, e.g., "config.k8s.io/v1beta1".
       APIVersion string `json:"apiVersion"`
       // Standard object's metadata.
       // +optional
       Metadata metav1.ObjectMeta `json:"metadata,omitempty"`
       // Flags contains the command-line flags and their values.
       // The keys are the flag names and the values are the flag values,
       // possibly with confidential values redacted.
       // +optional
       Flags map[string]string `json:"flags,omitempty"`
}

/statusz 和 /flagz 的结构化响应在 v1.36 版本中处于 Beta 阶段,未来版本可能会有所更改。 它们旨在为调试和自省工具提供机器可解析的输出。

来源:Kubernetes 文档贡献者 · 作者与贡献记录 · CC BY 4.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
Kubernetes 文档贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。