Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Security Kubernetes Kubernetes: From Zero to Production Module 7 - Security

RBAC - Role-Based Access Control in Kubernetes

Reviewed & accurate
AI Summary

What You Will Learn

Intermediate

  • How RBAC works in K8s
  • Roles vs ClusterRoles
  • How to create and bind roles
ObjectScopeWhat it does
RoleNamespaceDefines permissions in one namespace
ClusterRoleCluster-wideDefines permissions across all namespaces
RoleBindingNamespaceBinds a Role to a user/service
ClusterRoleBindingCluster-wideBinds a ClusterRole to a user/service
rbac.yamlyaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: production
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: production
subjects:
- kind: ServiceAccount
  name: my-app
  namespace: production
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Practical Exercise

Create a Role that can only read Pods
Create a RoleBinding to bind it to a ServiceAccount
Test: kubectl auth can-i list pods --as=system:serviceaccount:default:my-app
Create a ClusterRole for cluster-wide read access

Key Takeaways

  • RBAC: Role + RoleBinding (namespace). ClusterRole + ClusterRoleBinding (cluster).
  • Role: defines permissions (what verbs on what resources).
  • RoleBinding: binds Role to a user/ServiceAccount.
  • Principle of least privilege: give minimum permissions.
  • kubectl auth can-i: test permissions.
Previously: Module 6 covered scaling.
Today: You learned: Control who can do what in K8s.
Next: Lesson 37 covers ServiceAccounts.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments