Prometheus无法监控kubernetes中的所有Pod

时间:2018-06-29 00:46:20

标签: kubernetes prometheus

因此,当我在kubernetes上部署prometheus时,我有3个名称空间,我在日志中看到错误。它无法监视所有名称空间。

错误:

\“ system:serviceaccount:development:default \”无法列出集群范围内的端点“ 等级=错误ts = 2018-06-28T21:22:07.390161824Z呼叫者= main.go:216组件= k8s_client_runtime err =“ github.com/prometheus/prometheus/discovery/kubernetes/kubernetes.go:268:无法列出* v1.Endpoints:禁止端点:用户\“ system:serviceaccount:devops:default \”无法列出集群范围内的端点“

1 个答案:

答案 0 :(得分:0)

您最好使用服务帐户来访问kubernetes,并赋予prometheus所需的特殊特权。类似于以下内容:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus

---

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: prometheus
rules:
- apiGroups: [""]
  resources:
  - nodes
  - services
  - endpoints
  - pods
  verbs: ["get", "list", "watch"]
- apiGroups: [""]
  resources:
  - configmaps
  verbs: ["get"]
- nonResourceURLs: ["/metrics"]
  verbs: ["get"]

---

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: prometheus
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: prometheus
subjects:
- kind: ServiceAccount
  name: prometheus
  namespace: kube-system

假定您在kube-system名称空间中部署了普罗米修斯。另外,您还需要在Prometheus部署文件中指定类似“ serviceAccount:prometheus”之类的文件。