πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Security intermediate ⏱ 15 minutes K8s 1.28+

Kubernetes RBAC: Roles, ClusterRoles, and Bindings

Configure Kubernetes RBAC with Roles, ClusterRoles, RoleBindings, and service accounts. Least privilege access control for users, groups, and applications.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: Configure Kubernetes RBAC with Roles, ClusterRoles, RoleBindings, and service accounts. Least privilege access control for users, groups, and applications.

The Problem

This is one of the most searched Kubernetes topics. A comprehensive, well-structured guide helps engineers of all levels quickly find actionable solutions.

The Solution

Detailed implementation with production-ready examples below.

RBAC Components

# Role β€” namespace-scoped permissions
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: default
rules:
  - apiGroups: [""]
    resources: ["pods", "pods/log"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["apps"]
    resources: ["deployments"]
    verbs: ["get", "list"]
---
# RoleBinding β€” grants Role to user/group/SA
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: default
subjects:
  - kind: User
    name: jane
    apiGroup: rbac.authorization.k8s.io
  - kind: Group
    name: developers
    apiGroup: rbac.authorization.k8s.io
  - kind: ServiceAccount
    name: my-app
    namespace: default
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io
---
# ClusterRole β€” cluster-wide permissions
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: secret-reader
rules:
  - apiGroups: [""]
    resources: ["secrets"]
    verbs: ["get", "list"]
  - apiGroups: [""]
    resources: ["namespaces"]
    verbs: ["get", "list"]
---
# ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: read-secrets-global
subjects:
  - kind: Group
    name: sre-team
    apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: secret-reader
  apiGroup: rbac.authorization.k8s.io

Test Permissions

# Check what you can do
kubectl auth can-i create deployments
kubectl auth can-i delete pods --namespace production

# Check as another user
kubectl auth can-i get secrets --as jane
kubectl auth can-i get secrets --as system:serviceaccount:default:my-app

# List all permissions
kubectl auth can-i --list
kubectl auth can-i --list --as jane --namespace default

Common RBAC Patterns

PatternRole TypeScope
Dev read-onlyRolePer namespace
Dev deploy accessRolePer namespace
SRE full accessClusterRoleCluster-wide
CI/CD deployRole + SAPer namespace
MonitoringClusterRoleRead pods/nodes cluster-wide
graph TD
    A[User/Group/SA] --> B[RoleBinding]
    B --> C[Role - namespace scoped]
    A --> D[ClusterRoleBinding]
    D --> E[ClusterRole - cluster scoped]
    C --> F[Permissions in one namespace]
    E --> G[Permissions across all namespaces]

Frequently Asked Questions

Role vs ClusterRole?

Role grants permissions in a single namespace. ClusterRole grants permissions cluster-wide or across all namespaces. Use ClusterRole + RoleBinding to reuse a ClusterRole in a specific namespace.

How do I debug RBAC denied errors?

Check the API server audit log or run kubectl auth can-i as the failing identity. Common issue: forgot to create the RoleBinding (Role alone does nothing).

Common Issues

Check kubectl describe and kubectl get events first β€” most issues have clear error messages pointing to the root cause.

Best Practices

  • Follow least privilege β€” only grant the access that’s needed
  • Test in staging before applying to production
  • Monitor and alert on key metrics
  • Document your runbooks for the team

Key Takeaways

  • Essential knowledge for Kubernetes operations
  • Start simple and evolve your approach
  • Automation reduces human error
  • Share knowledge with your team
#rbac #roles #clusterrole #rolebinding #access-control #kubernetes
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens