otel/opentelemetry-collector-k8sOpenTelemetry Collector (k8s) 镜像为 Kubernetes 环境定制,是 OpenTelemetry 可观测性数据处理管道的核心组件。该镜像整合了 open-telemetry/opentelemetry-collector 仓库的核心组件及contrib 扩展组件,专为在 Kubernetes 集群中运行设计,提供可观测性数据(traces、metrics、logs)的统一收集、处理、转换与导出能力。
bashdocker run -d \ --name otel-collector-k8s \ -p 4317:4317 # OTLP gRPC 接收器端口 \ -p 4318:4318 # OTLP HTTP 接收器端口 \ -p 8888:8888 # 指标暴露端口(用于自身监控) \ -v /path/to/otel-collector-config.yaml:/etc/otelcol/config.yaml \ otel/opentelemetry-collector-k8s:latest
注:
otel/opentelemetry-collector-k8s为官方镜像名称,实际使用时需替换为具体版本标签(如0.91.0)。
yamlversion: '3' services: otel-collector: image: otel/opentelemetry-collector-k8s:latest container_name: otel-collector-k8s ports: - "4317:4317" # OTLP gRPC - "4318:4318" # OTLP HTTP - "8888:8888" # 自身指标暴露 volumes: - ./otel-collector-config.yaml:/etc/otelcol/config.yaml environment: - OTEL_LOG_LEVEL=info # 日志级别:debug/info/warn/error restart: unless-stopped
推荐通过 Deployment 或 DaemonSet 部署(根据数据收集范围选择),以下为 Deployment 示例:
1. 创建配置文件 ConfigMap
otel-collector-config.yaml:
yamlapiVersion: v1 kind: ConfigMap metadata: name: otel-collector-config namespace: observability data: config.yaml: | receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 http: endpoint: 0.0.0.0:4318 prometheus: config: scrape_configs: - job_name: 'otel-collector' static_configs: - targets: ['localhost:8888'] processors: batch: # 批量处理以减少导出请求数 resourcedetection: # 自动添加 Kubernetes 资源元数据 detectors: [k8s] timeout: 10s override: false exporters: logging: # 控制台输出(调试用) loglevel: info prometheusremotewrite: # 导出至 Prometheus endpoint: "[***]" service: pipelines: traces: receivers: [otlp] processors: [batch, resourcedetection] exporters: [logging] metrics: receivers: [otlp, prometheus] processors: [batch, resourcedetection] exporters: [logging, prometheusremotewrite]
2. 创建 Deployment
otel-collector-deployment.yaml:
yamlapiVersion: apps/v1 kind: Deployment metadata: name: otel-collector namespace: observability spec: replicas: 1 selector: matchLabels: app: otel-collector template: metadata: labels: app: otel-collector spec: containers: - name: otel-collector image: otel/opentelemetry-collector-k8s:latest resources: limits: cpu: 1000m memory: 1Gi requests: cpu: 200m memory: 256Mi ports: - containerPort: 4317 # OTLP gRPC - containerPort: 4318 # OTLP HTTP - containerPort: 8888 # 自身指标 volumeMounts: - name: config-volume mountPath: /etc/otelcol/config.yaml subPath: config.yaml env: - name: OTEL_LOG_LEVEL value: "info" - name: K8S_NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName volumes: - name: config-volume configMap: name: otel-collector-config
Collector 通过配置文件(默认路径 /etc/otelcol/config.yaml)定义数据处理流程,核心配置项包括:
| 配置项 | 说明 |
|---|---|
receivers | 定义数据来源(如 OTLP、Prometheus、Jaeger、Filelog 等),每个接收器含特定配置(端口、协议、采集规则)。 |
processors | 定义数据处理逻辑(如 batch 批量处理、filter 数据过滤、resourcedetection 元数据添加、sampling 采样等)。 |
exporters | 定义数据导出目标(如 logging 控制台、otlp 远程 OTLP 服务、prometheusremotewrite Prometheus 写入接口、jaeger Jaeger 后端等)。 |
service | 定义数据管道(pipelines),将接收器、处理器、导出器关联,按数据类型(traces/metrics/logs)划分。 |
Collector 支持通过环境变量调整运行时行为,常用变量:
| 变量名 | 说明 | 默认值 |
|---|---|---|
OTEL_CONFIG_FILE | 配置文件路径 | /etc/otelcol/config.yaml |
OTEL_LOG_LEVEL | 日志级别(debug/info/warn/error) | info |
OTEL_RESOURCE_ATTRIBUTES | 全局资源属性(键值对,如 service.name=my-service,cluster=prod) | 空 |
K8S_NODE_NAME | Kubernetes 节点名称(用于 resourcedetection 处理器,通常通过 downward API 注入) | 自动从节点元数据获取 |

manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务