我們有一個共享租戶集群,我們希望我們的開發人員能夠運行 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 似乎作業正常。
uj5u.com熱心網友回復:
Kubernetes 有 API 組metrics.k8s.io,您可以使用它來授予kubectl top pods -n <namespace>. 如果您授予get并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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/348880.html
標籤:Kubernetes
