Kubectl Role-Based Access Control (RBAC) is how you decide who can see what, and who can change what, in Kubernetes. Without it, every kubectl command is a loaded weapon. With it, you get fine-grained control at scale.
RBAC in Kubernetes works by binding Roles or ClusterRoles to Subjects—users, groups, or service accounts—through RoleBindings or ClusterRoleBindings. Roles define allowed actions on resources. Bindings attach those permissions to specific identities. You enforce this with YAML files or kubectl commands.
Core RBAC Components
- Role: Grants permissions within a single namespace.
- ClusterRole: Grants permissions cluster-wide.
- RoleBinding: Links a Role to a subject in a specific namespace.
- ClusterRoleBinding: Links a ClusterRole to a subject across the whole cluster.
Creating an RBAC Role with kubectl
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: dev
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
Apply it: