Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes "pods.metrics.k8s.io "my-pod-name" is forbidden: User "system:serviceaccount:default:default" cannot get resource "pods"

I can't figure out whats wrong with my role binding. I keep getting this error while trying to get metrics for my pod.

"pods.metrics.k8s.io "my-pod-name" is forbidden: User "system:serviceaccount:default:default" cannot get resource "pods" in API group "metrics.k8s.io" in the namespace "default""

Here is the Cluster role yaml file

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: pod-reader
rules:
  - apiGroups: ["", "metrics.k8s.io"] # "" indicates the core API group
    resources: ["pods"]
    verbs: ["get", "watch", "list"]

Then I ran this command

kubectl create clusterrolebinding pod-reader \
  --clusterrole=pod-reader  \
  --serviceaccount=default:default
like image 257
Daniel Kobe Avatar asked Oct 28 '25 08:10

Daniel Kobe


1 Answers

ClusterRole & ClusterRolebinding are non-namespaced resources. So, remove the namespace line from your YAML file.

Alternatively, use Role & RoleBinding if you want to scope to a namespace.

like image 60
Nathan Avatar answered Oct 30 '25 06:10

Nathan