What it means
Kubernetes knows who you are, but no Role or ClusterRole bound to you grants that verb on that resource in that namespace. The error names the user, verb, resource and namespace: everything you need to write the rule.
Causes and fixes
Most likely first. Run the check, and if it matches, apply the fix.
1. No RoleBinding for that user or ServiceAccount in the namespace
Check:
kubectl auth can-i list pods -n <ns> --as=<user>
kubectl get rolebindings -n <ns> -o wide
Fix: Create a Role with the verbs it needs and a RoleBinding to the subject.
2. The binding exists but in another namespace, or names the wrong subject (ServiceAccount namespace, user name)
Check:
kubectl describe rolebinding <name> -n <ns>
Fix: Bind in the namespace where the access is needed, with the exact subject.
3. The Role misses the resource, verb or API group (deployments are in apps)
Check:
kubectl describe role <role> -n <ns>
Fix: Add the missing verb or apiGroup; check with kubectl auth can-i.
Fix it yourself
A live machine in your browser with this problem already on it. The grader checks the result.
- Give a ServiceAccount Read-Only Accessmedium 8 min
- A Role for Rolling Out Appsmedium 8 min
- Forbidden, Even With a RolePromedium 10 min
No account needed for your first tries.
Related errors
- The connection to the server localhost:8080 was refused - did you specify the right host or port?
kubectl found no kubeconfig and fell back to localhost:8080.