Kubernetes RBAC and Service Accounts
What you'll learn: How to control who (and what) can do what inside your Kubernetes cluster using role-based access control and service accounts.
The Core Idea
In Kubernetes, RBAC (Role-Based Access Control) is the gatekeeper that determines which users or processes can perform specific actions on cluster resources. Think of it like a corporate office building: service accounts are ID badges that applications wear, roles define what each badge level can access (read files, enter server rooms, etc.), and role bindings connect badges to permissions.
Service Accounts
Service accounts are identities for pods and applications running inside your cluster—not for humans. Every pod runs with a service account (a default one if you don't specify). When your containerized app needs to call the Kubernetes API or access other resources, it authenticates using this service account's token, which is automatically mounted into the pod.
apiVersion: v1
kind: ServiceAccount
metadata:
name: app-reader
namespace: production
RBAC Components
Roles define permissions (verbs like get, list, create on resources like pods, secrets). RoleBindings attach those permissions to service accounts. Use Role and RoleBinding for namespace-scoped access, ClusterRole and ClusterRoleBinding for cluster-wide.
Principle of Least Privilege
Grant only the minimum permissions needed. If your app only reads ConfigMaps, don't give it permission to delete pods. Overly permissive service accounts are common attack vectors—if a pod is compromised, excessive permissions let attackers pivot deeper into your cluster.
Key Takeaway: Kubernetes RBAC and service accounts enforce the principle of least privilege by giving each workload only the specific permissions it needs, reducing blast radius if a container is compromised.