gitlab prometheus Failed to list *v1.Node: nodes is forbidden: User \“system:serviceaccount:default:

文章讲述了GitLab启动时Prometheus因权限问题在Kubernetes中收集指标失败的情况,介绍了关闭内置Prometheus监控K8s功能的三种方法:修改gitlab.rb配置、环境变量设置和调整RBAC权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

gitlab 启动报错:

`==> /var/log/gitlab/prometheus/current <==
2023-12-07_05:10:36.23823 level=error ts=2023-12-07T05:10:36.238Z caller=klog.go:94 component=k8s_client_runtime func=ErrorDepth msg="github.com/prometheus/prometheus/discovery/kubernetes/kubernetes.go:335: Failed to list *v1.Node: nodes is forbidden: User \"system:serviceaccount:auser:default\" cannot list resource \"nodes\" in API group \"\" at the cluster scope"
2023-12-07_05:10:36.23845 level=error ts=2023-12-07T05:10:36.238Z caller=klog.go:94 component=k8s_client_runtime func=ErrorDepth msg="github.com/prometheus/prometheus/discovery/kubernetes/kubernetes.go:283: Failed to list *v1.Pod: pods is forbidden: User \"system:serviceaccount:auser:default\" cannot list resource \"pods\" in API group \"\" at the cluster scope"

原因:如果 GitLab 服务器在 Kubernetes 中运行,则 Prometheus 将从群集中的节点和带注释的 Pod 收集指标,包括每个容器上的性能数据.。
但是 gitlab运行在 自定义namespace中,默认没权限访问k8s的资源,导致内置的prometheus获取k8s信息报错。

解决:关闭gitlab里内置prometheus监控k8s的功能
方式一:修改 /etc/gitlab/gitlab.rb
在这里插入图片描述

方式二:通过添加环境变量关闭

env:
- name: GITLAB_OMNIBUS_CONFIG
  value: "prometheus['monitor_kubernetes'] = false"

方式三:当然也可以给 prometheus 放开 K8S 的RBAC权限。(因为这是GitLab内置的Prometheus,实际上k8s超过了其监控范围,不建议这么配。如果是独立Prometheus比较合适)
参考:https://github.com/prometheus-operator/prometheus-operator/issues/2155

参考:
https://gitlab.com/gitlab-org/gitlab/-/issues/34405
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-config-template/gitlab.rb.template

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值