Understanding Kubernetes ClusterRoles and ClusterRoleBindings

Understanding Kubernetes ClusterRoles and ClusterRoleBindings

1 3 13
calendar_today agoschedule1 min read

Yesterday I learned about Roles and RoleBindings. Today I explored ClusterRoles and ClusterRoleBindings for cluster-scoped resources like Nodes.

Why a Role Wasn't Enough

kubectl auth can-i get nodes

Output:

Warning: resource 'nodes' is not namespace scoped
no

Nodes are cluster-scoped resources, so a namespace Role cannot grant access.

Creating a ClusterRole

kubectl create clusterrole node-reader --verb=get,list,watch --resource=nodes

Verify:

kubectl get clusterrole | grep node-reader

Creating a ClusterRoleBinding

I first made a mistake:

kubectl create clusterrolebinding reader-binding --clusterrole=cluster-reader --user=adeoye

Checking permissions:

kubectl auth can-i get nodes --as adeoye

returned:

no - RBAC: clusterrole.rbac.authorization.k8s.io "cluster-reader" not found

The binding referenced a ClusterRole that didn't exist.

I fixed it by deleting and recreating the binding:

kubectl delete clusterrolebinding reader-binding
kubectl create clusterrolebinding reader-binding --clusterrole=node-reader --user=adeoye

Now:

kubectl auth can-i get nodes --as adeoye

returned:

yes

Testing as adeoye

kubectl config use-context adeoye
kubectl get nodes

Listing nodes worked.

Describing a node:

kubectl describe node cka-cluster3-worker

showed most information, but RBAC blocked access to leases and pods because the ClusterRole only granted access to nodes.

Trying to delete a node:

kubectl delete node cka-cluster3-worker

returned Forbidden because the ClusterRole only included get, list, and watch.

Key Takeaways

  • Roles are namespace-scoped.
  • ClusterRoles are cluster-scoped.
  • ClusterRoleBindings grant cluster-wide permissions.
  • RBAC permissions are resource-specific.
  • Kubernetes follows the principle of least privilege.
Part 5 of 6 in My Kubernetes Journey
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

Understanding Kubernetes RBAC: Roles, RoleBindings, and and Client Certificates

AYANFE - Jul 6

Understanding Kubernetes Service Accounts (The Identity Every Pod Uses)

AYANFE - Jul 7

Kubernetes Autoscaling: HPA vs VPA Explained With Hands-On Practice

AYANFE - Jul 1

Check out this article for beginners on Kubernetes

Onlyfave - Jan 17, 2025

How Kubernetes Simplifies Cloud Application Deployment, Scaling, and Management

Aditya Pratap Bhuyan - Mar 13, 2025
chevron_left
308 Points17 Badges
Abuja,Nigeria.
8Posts
3Comments
5Connections
A gentleman with a rough edge.

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!