kubernetes - k8s 命名空间管理员如何使用 top?
问题描述
我们有一个共享租户集群,我们希望我们的开发人员能够运行kubectl top pods --namespace dev-namespace
但在我看来,要使 top 可用,您需要能够运行kubectl get nodes
. 但是节点没有命名空间。
有解决办法吗?
我们的命名空间管理员设置如下:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: admin
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: username@domain
作为集群管理员,我可以运行 top 命令,因此 metrics-server 似乎工作正常。
解决方案
Kubernetes 有 API 组metrics.k8s.io
,您可以使用它来授予对kubectl top pods -n <namespace>
. 如果您授予podget
和list
权限,则可以运行该命令。
我在运行 Kubernetes 1.21 的 GKE 集群中测试了以下配置,其中kubectl top pod --as=system:serviceaccount:monitoring:test-account -n monitoring
. 有了这些权限,我只能kubectl top pod
在monitoring
命名空间中运行,其他命令会失败。
apiVersion: v1
kind: ServiceAccount
metadata:
name: test-account
namespace: monitoring
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
namespace: monitoring
rules:
- apiGroups: ["metrics.k8s.io"]
resources: ["pods"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
namespace: monitoring
subjects:
- kind: ServiceAccount
name: test-account
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
推荐阅读
- firebase - 如何将图像复制到 Firebase 存储中的另一个参考路径?
- javascript - 如何将元素附加到 div?
- syntax - 使用累加器连接数字列表
- firebase - 如何仅重新渲染 Flatlist 中的一项?
- c++ - 如何在 Windows 上的控制台应用程序中显示 UTF-8 而无需用户更改控制台中的任何内容?
- r - 用 R 按一组间隔计算两列中的条目数
- r - 如何协调 purrr::map 与 case_when
- javascript - 当元素在视图中时,Slick-Carousel 自动播放开始
- python - 请解释此代码 list = ' '.join(i for i in list_text_from_file if not i in chars)
- vue.js - 基于项目类型的 Vuetify 格式单元格