π§ Concept 18: Security (RBAC + Service Accounts + Production π)




π 1. Core Idea (1-line)
π Kubernetes security controls who can do what using RBAC + Service Accounts
π§ 2. Why Security is Needed (VERY IMPORTANT β οΈ)
Without RBAC:
-
Anyone can delete pods β
-
Anyone can access secrets β
-
Cluster = unsafe π
π 3. Authentication vs Authorization (MUST KNOW π₯)
π Authentication β βWho are you?β
- User / Service Account
π‘οΈ Authorization β βWhat can you do?β
- RBAC decides this
βοΈ 4. RBAC (Role-Based Access Control)
π’ 1. Role
π Defines permissions inside a namespace
kind: Role
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]π΅ 2. RoleBinding
π Assigns role to user/service account
kind: RoleBinding
subjects:
- kind: User
name: yashπ 3. ClusterRole
π Same as Role but cluster-wide
π 4. ClusterRoleBinding
π Binds ClusterRole globally
π₯ 5. Flow (VERY IMPORTANT π₯)
User β API Server β RBAC check β Allowed / Deniedπ§ 6. Service Accounts (VERY IMPORTANT π₯)
π Used by pods to talk to Kubernetes API
Example:
apiVersion: v1
kind: ServiceAccount
metadata:
name: my-saπ Attach to pod:
spec:
serviceAccountName: my-saπ₯ 7. Real-world Example
Pod wants to:
-
Read secrets
-
Access API
π Needs:
-
Service Account
-
Proper Role
β οΈ 8. VERY IMPORTANT Security Rules
-
Never give
cluster-adminβ -
Follow least privilege principle
-
Rotate secrets
π 9. Secrets Security (Advanced)
Earlier we saw Secrets π
π For production:
-
Enable encryption at rest
-
Use:
-
AWS Secrets Manager
-
HashiCorp Vault
π₯ 10. Real DevOps Insight
In companies:
-
Dev β limited access
-
CI/CD β controlled access
-
Apps β service accounts
π Everything controlled via RBAC
β οΈ 11. Common Mistakes
β Giving full access
β Not using service accounts
β Hardcoding credentials
πΌ 12. Interview Answer
π βKubernetes security is implemented using RBAC for authorization and Service Accounts for pod-level identity, ensuring controlled and secure access to cluster resources.β
β‘ 13. CKA Commands
kubectl get roles
kubectl get rolebindings
kubectl get serviceaccountsπ§ 14. Memory Trick
π RBAC = permissions π«
π Service Account = identity π
π₯ 15. Pro Insight (Real-world)
π Combine:
-
RBAC
-
Network Policies
-
Pod Security
π For full cluster security π
π Next Step
Bol:
π βnextβ
Then we go to FINAL:
π₯ Concept 19: Troubleshooting (Debugging K8s like a PRO π― β MOST IMPORTANT FOR CKA π₯)