Files
Work-configuration-file/OpenTelemetry/Collector_v3/06-otel-agent.yaml
2026-01-27 18:21:17 +08:00

55 lines
1.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel-agent
namespace: monitoring
spec:
mode: daemonset
image: otel/opentelemetry-collector-contrib:0.144.0
serviceAccount: otel-collector-sa
env:
- name: K8S_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
# --- 新增在这里定义集群名称Prod 环境改一下这个值即可 ---
- name: CLUSTER_NAME
value: "test-k8s-cluster"
config:
receivers:
hostmetrics:
collection_interval: 30s
scrapers:
cpu: {}
memory: {}
kubeletstats:
collection_interval: 30s
auth_type: "serviceAccount"
endpoint: "https://${env:K8S_NODE_NAME}:10250"
insecure_skip_verify: true
processors:
batch: {}
resourcedetection:
detectors: [env, system, k8snode]
# --- 新增:强制给所有指标打上集群名称标签 ---
resource:
attributes:
- key: k8s.cluster.name
value: ${env:CLUSTER_NAME}
action: insert
exporters:
otlp:
endpoint: "otel-gateway-collector.monitoring.svc.cluster.local:4317"
tls:
insecure: true
service:
pipelines:
metrics:
receivers: [hostmetrics, kubeletstats]
# 注意:这里要加上 resource 处理器
processors: [resourcedetection, resource, batch]
exporters: [otlp]