kubernetes - 使用 RBAC for Grafana 在 Kubernetes 中创建集群范围的只读用户
问题描述
我正在尝试配置用户,以便 Grafana 能够监控我的集群资源。我在这里遵循了 Bitnami 指南。并将这些步骤作为 Ansible 剧本实施在这里。
这是用户使用的 ClusterRole,也是它与用户的绑定方式。
但是,尽管如此,当我使用生成的证书对其进行配置时,Grafana 仍会引发此错误。
此外,如果我尝试使用用户上下文运行任何命令,它会说我未经授权。
$> kubectl --context=grafana-prometheus-scraper get pods -n grafana
error: You must be logged in to the server (Unauthorized)
有任何想法吗?
解决方案
这就是您的 ServiceAccount、ClusterRole 和 ClusterRoleBinding的样子。
apiVersion: v1
kind: ServiceAccount
metadata:
name: grafana-prometheus-scraper
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: grafana-prometheus-scraper
rules:
- apiGroups: [""]
resources:
- configmaps
- secrets
- nodes
- pods
- services
- resourcequotas
- replicationcontrollers
- limitranges
- persistentvolumeclaims
- persistentvolumes
- namespaces
- endpoints
verbs: ["list", "watch"]
- apiGroups: ["extensions"]
resources:
- daemonsets
- deployments
- replicasets
- ingresses
verbs: ["list", "watch"]
- apiGroups: ["apps"]
resources:
- daemonsets
- deployments
- replicasets
- statefulsets
verbs: ["list", "watch"]
- apiGroups: ["batch"]
resources:
- cronjobs
- jobs
verbs: ["list", "watch"]
- apiGroups: ["autoscaling"]
resources:
- horizontalpodautoscalers
verbs: ["list", "watch"]
- apiGroups: ["policy"]
resources:
- poddisruptionbudgets
verbs: ["list", "watch"]
- apiGroups: ["certificates.k8s.io"]
resources:
- certificatesigningrequests
verbs: ["list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources:
- storageclasses
verbs: ["list", "watch"]
- apiGroups: ["autoscaling.k8s.io"]
resources:
- verticalpodautoscalers
verbs: ["list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: grafana-prometheus-scraper
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: grafana-prometheus-scraper
subjects:
- kind: ServiceAccount
name: grafana-prometheus-scraper
创建集群角色时不必指定命名空间,因为这适用于整个集群。如果你想限制对特定命名空间的访问,你应该使用 Role 和 RoleBinding。
关于为您的 Kubernetes 服务帐户配置 RBAC的 Medium 上有一篇非常好的文章,我强烈推荐。
推荐阅读
- bash - bash用变量值替换字符串中的变量名
- react-leaflet - 不显示图像叠加
- c# - 原子符号链接替换windows c#抛出IOException“此应用程序不支持符号链接上的当前操作”
- javascript - Bootstrap 4 下拉菜单通过悬停出现
- python - {“错误”:“格式错误的请求:POST /v1/models/text_model”} Tensorflow 服务
- javascript - 如何在卡片末尾对齐项目,垂直居中(使用引导程序 4)?
- woocommerce - 仅显示 WooCommerce 父属性
- angular - 从组件到组件获取数据?(角度)
- r - 根据条件使用 left_join 合并数据
- reactjs - 如果我有 useState,则重新安装反应功能组件