在 k8s 集群中部署 kube-prometheus 后遇到下面的问题
查看 prometheus 日志:
kubectl logs prometheus-k8s-0 -n monitoring -c prometheus | tail
发现下面的错误:
Failed to list *v1.Pod: pods is forbidden: User \"system:serviceaccount:monitoring:prometheus-k8s\" cannot list resource \"pods\" in API group \"\" at the cluster scope
请问如何解决?
在园子里的博文 PrometheusOperator服务自动发现-监控redis样例 中找到了解决方法,将 prometheus-clusterRole.yaml 改为下面的配置
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus-k8s
rules:
- apiGroups:
  - ""
  resources:
  - nodes
  - services
  - endpoints
  - pods
  - nodes/proxy
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - configmaps
  - nodes/metrics
  verbs:
  - get
- nonResourceURLs:
  - /metrics
  verbs:
  - get
重新部署即可
kubectl apply -f prometheus-clusterRole.yaml