Files
Work-configuration-file/OpenTelemetry/Collector /01-otel-rbac.yaml
2026-01-09 17:50:32 +08:00

56 lines
1.4 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.

# 1. 创建monitoring命名空间
apiVersion: v1
kind: Namespace
metadata:
name: monitoring
labels:
name: monitoring
---
# 2. 创建ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
name: otel-collector
namespace: monitoring
---
# 3. 创建ClusterRole最小权限
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: otel-collector-role
rules:
# 读取节点/Pod/服务元数据(基础权限)
- apiGroups: [""]
resources: ["nodes", "pods", "services", "endpoints", "nodes/metrics", "nodes/stats"]
verbs: ["get", "list", "watch"]
# 后续增加
# # 新增采集Deployment/DaemonSet/StatefulSetapps API组
# - apiGroups: ["apps"]
# resources: ["deployments", "daemonsets", "statefulsets", "replicasets"]
# verbs: ["get", "list", "watch"]
# # 新增采集HPAautoscaling API组
# - apiGroups: ["autoscaling"]
# resources: ["horizontalpodautoscalers"]
# verbs: ["get", "list", "watch"]
# # 新增采集k8s事件可选用于故障排查
# - apiGroups: [""]
# resources: ["events"]
# verbs: ["get", "list", "watch"]
---
# 4. 绑定ClusterRole到ServiceAccount
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: otel-collector-binding
subjects:
- kind: ServiceAccount
name: otel-collector
namespace: monitoring
roleRef:
kind: ClusterRole
name: otel-collector-role
apiGroup: rbac.authorization.k8s.io