DevOps Dictionary

Kubernetes ClusterRole

Kubernetes ClusterRole is a cluster-wide Role-Based Access Control, or RBAC, object that defines what actions are allowed against Kubernetes resources. It can describe permissions for cluster-scoped resources like Nodes and PersistentVolumes, and it can also define reusable permissions for namespaced resources like Pods, Deployments, and Services.

What a ClusterRole does

A ClusterRole defines a set of permissions. It does not grant those permissions by itself. Kubernetes grants the permissions only when you attach the ClusterRole to a user, group, or ServiceAccount using a binding.

Common permissions include:

  • Read access, such as get, list, and watch on Pods or Nodes.
  • Write access, such as create, update, patch, and delete on Deployments or ConfigMaps.
  • Administrative access to cluster-level resources, such as Namespaces, Nodes, ClusterRoles, and CustomResourceDefinitions.
  • Access to non-resource URLs, such as /healthz or /metrics.

How it works

A ClusterRole contains RBAC rules. Each rule usually includes:

  • apiGroups: The API group, such as apps, batch, or an empty string for core resources like Pods and Services.
  • resources: The Kubernetes resources covered by the rule, such as pods, deployments, or nodes.
  • verbs: The allowed actions, such as get, list, watch, create, or delete.
  • resourceNames: Optional. Limits access to specific object names.
  • nonResourceURLs: Optional. Grants access to API server paths that are not Kubernetes objects.

Example ClusterRole:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: pod-reader
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]

This object defines read-only access to Pods across the cluster, but nobody receives that access until it is bound.

ClusterRoleBinding and RoleBinding

You grant a ClusterRole with either a ClusterRoleBinding or a RoleBinding:

  • ClusterRoleBinding: Grants the ClusterRole across the whole cluster.
  • RoleBinding: Grants the ClusterRole only inside one namespace.

For example, you can create one ClusterRole named pod-reader and bind it with RoleBindings in dev, staging, and prod. This keeps the permission definition consistent while limiting where each team can use it.

ClusterRole vs Role

A Role belongs to one namespace and can grant access only within that namespace. A ClusterRole is cluster-scoped and can grant access to cluster-level resources, or serve as a reusable permission template for multiple namespaces.

Use a Role when the permission is specific to one namespace. Use a ClusterRole when you need access to cluster-scoped resources, or when you want one shared permission definition across many namespaces.

Common use cases

  • Platform team access: Allow SREs or platform engineers to inspect Nodes, Namespaces, PersistentVolumes, and cluster events.
  • Controller permissions: Grant operators and controllers the access they need to watch and reconcile resources.
  • CI/CD deployments: Give a deployment ServiceAccount permission to create or update workloads in selected namespaces.
  • Read-only observability: Let monitoring tools list Pods, Services, Endpoints, and Nodes without granting write access.
  • Multi-namespace access: Reuse one permission set across multiple app namespaces with separate RoleBindings.

Real-world example

A startup runs several teams on one Kubernetes cluster. The platform team wants developers to inspect Pods, logs, and Deployments in their own namespaces, but not edit cluster-wide objects like Nodes or ClusterRoles.

The platform team can create a ClusterRole with read-only access to common workload resources. Then it can create RoleBindings in each team namespace. Developers get consistent read access where they need it, while cluster administration remains restricted.

The same pattern applies when managing Kubernetes resources through infrastructure workflows, such as deploying Kubernetes resources using Terraform, where RBAC objects should be reviewed and version-controlled like other production configuration.

Benefits

  • Central permission definitions: Define a permission set once and reuse it across namespaces.
  • Least privilege: Grant only the verbs and resources a user or workload needs.
  • Clear separation of duties: Keep cluster administration separate from application deployment permissions.
  • Better auditability: RBAC objects can be stored in Git and reviewed through pull requests.

Tradeoffs and limitations

  • Easy to overgrant: Verbs like * or resources like * can give much broader access than intended.
  • Bindings matter as much as roles: A safe ClusterRole can become risky if bound cluster-wide to the wrong subject.
  • RBAC does not replace admission control: ClusterRole controls who can call the API, but it does not validate whether a submitted workload is safe.
  • Custom resources need explicit access: Operators and platforms that use CRDs often require additional RBAC rules.

ClusterRoles for controllers and platforms

Many Kubernetes controllers need ClusterRoles because they watch resources across namespaces or manage cluster-scoped objects. For example, a controller that provisions cloud infrastructure through Kubernetes may need access to CustomResourceDefinitions, provider-specific custom resources, Secrets, and events.

This is common in workflows such as deploying AWS resources using Crossplane on Kubernetes, where the controller needs enough RBAC access to reconcile infrastructure definitions safely.

Operational guidance

  • Start with read-only verbs, then add write permissions only when required.
  • Avoid cluster-admin for applications, CI jobs, and controllers unless there is a clear, temporary reason.
  • Use separate ServiceAccounts for separate workloads instead of sharing one powerful account.
  • Review ClusterRoleBindings during access reviews, incident response, and Kubernetes upgrades.
  • Test permissions with kubectl auth can-i before rolling them out to production.

A Kubernetes ClusterRole is a core RBAC building block. Used carefully, it gives teams consistent, auditable access control across the cluster without giving every user or workload broad administrative permissions.

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
Y
X
Z