【问题标题】:prometheus cannot able to monitor all the pods in kubernetesprometheus 无法监控 kubernetes 中的所有 pod
【发布时间】:2018-06-29 00:46:19
【问题描述】:

所以当我在 kubernetes 上部署 prometheus 时,我有 3 个名称空间,我在日志中看到了错误。它无法监控所有的命名空间。

错误:

\"system:serviceaccount:development:default\" cannot list endpoints at the cluster scope"
level=error ts=2018-06-28T21:22:07.390161824Z caller=main.go:216 component=k8s_client_runtime err="github.com/prometheus/prometheus/discovery/kubernetes/kubernetes.go:268: Failed to list *v1.Endpoints: endpoints is forbidden: User \"system:serviceaccount:devops:default\" cannot list endpoints at the cluster scope"

【问题讨论】:

    标签: kubernetes prometheus


    【解决方案1】:

    您最好使用服务帐户来访问 kubernetes,并赋予 prometheus 所需的 sa 特殊权限。像下面这样:

    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。您还需要在 prometheus 部署文件中指定 sa 之类的 'serviceAccount: prometheus'。

    【讨论】:

    • 所以我有 4 个命名空间,kube-system、devlopment、default,并测试它如何适用于所有命名空间?我应该提一下吗?主题:- 种类:ServiceAccount 名称:prometheus 命名空间:kube-system
    • 在一个namespace中创建的service account可以监控所有namespace中的所有pod,这就是ClusterRole prometheus赋予的权限。
    猜你喜欢
    • 1970-01-01
    • 2021-02-12
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多