|
| 1 | +--- |
| 2 | +title: 追踪 Kubernetes 系统组件 |
| 3 | +content_type: concept |
| 4 | +weight: 60 |
| 5 | +--- |
| 6 | +<!-- |
| 7 | +--- |
| 8 | +title: Traces For Kubernetes System Components |
| 9 | +reviewers: |
| 10 | +- logicalhan |
| 11 | +- lilic |
| 12 | +content_type: concept |
| 13 | +weight: 60 |
| 14 | +--- |
| 15 | +--> |
| 16 | + |
| 17 | +<!-- overview --> |
| 18 | + |
| 19 | +{{< feature-state for_k8s_version="v1.22" state="alpha" >}} |
| 20 | + |
| 21 | +<!-- |
| 22 | +System component traces record the latency of and relationships between operations in the cluster. |
| 23 | +--> |
| 24 | +系统组件追踪功能记录各个集群操作的时延信息和这些操作之间的关系。 |
| 25 | + |
| 26 | +<!-- |
| 27 | +Kubernetes components emit traces using the |
| 28 | +[OpenTelemetry Protocol](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#opentelemetry-protocol-specification) |
| 29 | +with the gRPC exporter and can be collected and routed to tracing backends using an |
| 30 | +[OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector#-opentelemetry-collector). |
| 31 | +--> |
| 32 | +Kubernetes 组件基于 gRPC 导出器的 |
| 33 | +[OpenTelemetry 协议](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#opentelemetry-protocol-specification) |
| 34 | +发送追踪信息,并用 |
| 35 | +[OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector#-opentelemetry-collector) |
| 36 | +收集追踪信息,再将其转交给追踪系统的后台。 |
| 37 | + |
| 38 | +<!-- body --> |
| 39 | + |
| 40 | +<!-- |
| 41 | +## Trace Collection |
| 42 | +--> |
| 43 | +## 追踪信息的收集 {#trace-collection} |
| 44 | + |
| 45 | +<!-- |
| 46 | +For a complete guide to collecting traces and using the collector, see |
| 47 | +[Getting Started with the OpenTelemetry Collector](https://opentelemetry.io/docs/collector/getting-started/). |
| 48 | +However, there are a few things to note that are specific to Kubernetes components. |
| 49 | +--> |
| 50 | +关于收集追踪信息、以及使用收集器的完整指南,可参见 |
| 51 | +[Getting Started with the OpenTelemetry Collector](https://opentelemetry.io/docs/collector/getting-started/)。 |
| 52 | +不过,还有一些特定于 Kubernetes 组件的事项值得注意。 |
| 53 | + |
| 54 | +<!-- |
| 55 | +By default, Kubernetes components export traces using the grpc exporter for OTLP on the |
| 56 | +[IANA OpenTelemetry port](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=opentelemetry), 4317. |
| 57 | +As an example, if the collector is running as a sidecar to a Kubernetes component, |
| 58 | +the following receiver configuration will collect spans and log them to standard output: |
| 59 | +--> |
| 60 | +默认情况下,Kubernetes 组件使用 gRPC 的 OTLP 导出器来导出追踪信息,将信息写到 |
| 61 | +[IANA OpenTelemetry 端口](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=opentelemetry)。 |
| 62 | +举例来说,如果收集器以 Kubernetes 组件的边车模式运行,以下接收器配置会收集 spans 信息,并将它们写入到标准输出。 |
| 63 | + |
| 64 | +<!-- |
| 65 | +# Replace this exporter with the exporter for your backend |
| 66 | +--> |
| 67 | +```yaml |
| 68 | +receivers: |
| 69 | + otlp: |
| 70 | + protocols: |
| 71 | + grpc: |
| 72 | +exporters: |
| 73 | + # 用适合你后端环境的导出器替换此处的导出器 |
| 74 | + logging: |
| 75 | + logLevel: debug |
| 76 | +service: |
| 77 | + pipelines: |
| 78 | + traces: |
| 79 | + receivers: [otlp] |
| 80 | + exporters: [logging] |
| 81 | +``` |
| 82 | +
|
| 83 | +<!-- |
| 84 | +## Component traces |
| 85 | +
|
| 86 | +### kube-apiserver traces |
| 87 | +--> |
| 88 | +## 组件追踪 {#component-traces} |
| 89 | +
|
| 90 | +### kube-apiserver 追踪 {#kube-apiserver-traces} |
| 91 | +
|
| 92 | +<!-- |
| 93 | +The kube-apiserver generates spans for incoming HTTP requests, and for outgoing requests |
| 94 | +to webhooks, etcd, and re-entrant requests. It propagates the |
| 95 | +[W3C Trace Context](https://www.w3.org/TR/trace-context/) with outgoing requests |
| 96 | +but does not make use of the trace context attached to incoming requests, |
| 97 | +as the kube-apiserver is often a public endpoint. |
| 98 | +--> |
| 99 | +kube-apiserver 为传入的 HTTP 请求、传出到 webhook 和 etcd 的请求以及重入的请求生成 spans。 |
| 100 | +由于 kube-apiserver 通常是一个公开的端点,所以它通过出站的请求传播 |
| 101 | +[W3C 追踪上下文](https://www.w3.org/TR/trace-context/), |
| 102 | +但不使用入站请求的追踪上下文。 |
| 103 | +
|
| 104 | +<!-- |
| 105 | +#### Enabling tracing in the kube-apiserver |
| 106 | +--> |
| 107 | +#### 在 kube-apiserver 中启用追踪 {#enabling-tracing-in-the-kube-apiserver} |
| 108 | +
|
| 109 | +<!-- |
| 110 | +To enable tracing, enable the `APIServerTracing` |
| 111 | +[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) |
| 112 | +on the kube-apiserver. Also, provide the kube-apiserver with a tracing configration file |
| 113 | +with `--tracing-config-file=<path-to-config>`. This is an example config that records |
| 114 | +spans for 1 in 10000 requests, and uses the default OpenTelemetry endpoint: |
| 115 | +--> |
| 116 | +要启用追踪特性,需要启用 kube-apiserver 上的 `APIServerTracing` |
| 117 | +[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)。 |
| 118 | +然后,使用 `--tracing-config-file=<<配置文件路径>` 为 kube-apiserver 提供追踪配置文件。 |
| 119 | +下面是一个示例配置,它为万分之一的请求记录 spans,并使用了默认的 OpenTelemetry 端口。 |
| 120 | + |
| 121 | +```yaml |
| 122 | +apiVersion: apiserver.config.k8s.io/v1alpha1 |
| 123 | +kind: TracingConfiguration |
| 124 | +# default value |
| 125 | +#endpoint: localhost:4317 |
| 126 | +samplingRatePerMillion: 100 |
| 127 | +``` |
| 128 | + |
| 129 | +<!-- |
| 130 | +For more information about the `TracingConfiguration` struct, see |
| 131 | +[API server config API (v1alpha1)](/docs/reference/config-api/apiserver-config.v1alpha1/#apiserver-k8s-io-v1alpha1-TracingConfiguration). |
| 132 | +--> |
| 133 | +有关 TracingConfiguration 结构体的更多信息,请参阅 |
| 134 | +[API 服务器配置 API (v1alpha1)](/docs/reference/config-api/apiserver-config.v1alpha1/#apiserver-k8s-io-v1alpha1-TracingConfiguration)。 |
| 135 | + |
| 136 | +<!-- |
| 137 | +## Stability |
| 138 | +--> |
| 139 | +## 稳定性 {#stability} |
| 140 | + |
| 141 | +<!-- |
| 142 | +Tracing instrumentation is still under active development, and may change |
| 143 | +in a variety of ways. This includes span names, attached attributes, |
| 144 | +instrumented endpoints, etc. Until this feature graduates to stable, |
| 145 | +there are no guarantees of backwards compatibility for tracing instrumentation. |
| 146 | +--> |
| 147 | +追踪工具仍在积极开发中,未来它会以多种方式发生变化。 |
| 148 | +这些变化包括:span 名称、附加属性、检测端点等等。 |
| 149 | +此类特性在达到稳定版本之前,不能保证追踪工具的向后兼容性。 |
| 150 | + |
| 151 | +## {{% heading "whatsnext" %}} |
| 152 | + |
| 153 | +<!-- |
| 154 | +* Read about [Getting Started with the OpenTelemetry Collector](https://opentelemetry.io/docs/collector/getting-started/) |
| 155 | +--> |
| 156 | +* 阅读[Getting Started with the OpenTelemetry Collector](https://opentelemetry.io/docs/collector/getting-started/) |
0 commit comments