Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
RoleBindings and ClusterRoleBindings in Kubernetes
📖 Scenario: You are managing access control in a Kubernetes cluster. You need to assign permissions to users and groups so they can perform specific actions on resources.RoleBindings and ClusterRoleBindings connect users or groups to roles that define what they can do.
🎯 Goal: Create a RoleBinding and a ClusterRoleBinding to grant permissions to a user and a group respectively.
📋 What You'll Learn
Create a RoleBinding named read-pods-binding in the default namespace
Bind the view ClusterRole to the user alice using the RoleBinding
Create a ClusterRoleBinding named admin-group-binding
Bind the cluster-admin ClusterRole to the group admins using the ClusterRoleBinding
💡 Why This Matters
🌍 Real World
Kubernetes administrators use RoleBindings and ClusterRoleBindings to control who can do what in the cluster, ensuring security and proper access.
💼 Career
Understanding RBAC in Kubernetes is essential for DevOps engineers and cloud administrators managing secure and compliant Kubernetes environments.
Progress0 / 4 steps
1
Create a RoleBinding YAML skeleton
Create a YAML manifest for a RoleBinding named read-pods-binding in the default namespace. Include the apiVersion, kind, metadata with name and namespace, and an empty subjects and roleRef section.
Kubernetes
Hint
Start with the basic structure of a RoleBinding YAML manifest.
2
Add the user subject to the RoleBinding
Add a subjects entry to the RoleBinding with kind: User, name: alice, and apiGroup: rbac.authorization.k8s.io.
Kubernetes
Hint
Use a list item under subjects with the specified keys and values.
3
Set the roleRef to the view ClusterRole
Set the roleRef section with apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, and name: view.
Kubernetes
Hint
roleRef connects the RoleBinding to the ClusterRole named view.
4
Create a ClusterRoleBinding for the admins group
Create a YAML manifest for a ClusterRoleBinding named admin-group-binding. Bind the cluster-admin ClusterRole to the group admins by setting subjects with kind: Group, name: admins, and apiGroup: rbac.authorization.k8s.io. Set roleRef with apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, and name: cluster-admin. Print the full YAML manifest for this ClusterRoleBinding.
Kubernetes
Hint
ClusterRoleBinding is cluster-wide and binds a group to a ClusterRole.
Practice
(1/5)
1. What is the main difference between a RoleBinding and a ClusterRoleBinding in Kubernetes?
easy
A. RoleBinding and ClusterRoleBinding are exactly the same.
B. RoleBinding grants permissions cluster-wide, while ClusterRoleBinding grants permissions within a single namespace.
C. RoleBinding is used only for system users, ClusterRoleBinding is for regular users.
D. RoleBinding grants permissions within a single namespace, while ClusterRoleBinding grants permissions cluster-wide.
Solution
Step 1: Understand RoleBinding scope
RoleBinding assigns permissions only inside one namespace.
Step 2: Understand ClusterRoleBinding scope
ClusterRoleBinding assigns permissions across the entire cluster, not limited to a namespace.
Final Answer:
RoleBinding is namespace-scoped; ClusterRoleBinding is cluster-scoped. -> Option D
Quick Check:
Scope difference = RoleBinding grants permissions within a single namespace, while ClusterRoleBinding grants permissions cluster-wide. [OK]
Hint: ClusterRoleBinding with cluster-admin role = full cluster access [OK]
Common Mistakes:
Assuming permissions are limited to one namespace
Thinking only ServiceAccounts can be subjects
Confusing ClusterRoleBinding with RoleBinding scope
4. You applied this YAML to create a RoleBinding:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
subjects:
- kind: User
name: bob
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
But bob cannot list pods in the namespace. What is the likely problem?
medium
A. The subjects field is missing apiGroup for the user.
B. The roleRef kind should be ClusterRole instead of Role.
C. The RoleBinding must be created in the kube-system namespace.
D. The user bob does not exist in Kubernetes.
Solution
Step 1: Check subjects field completeness
The subjects entry for user bob lacks the required apiGroup field, which is needed to identify the user correctly.
Step 2: Understand impact of missing apiGroup
Without apiGroup, Kubernetes cannot match the user to the RoleBinding, so permissions are not granted.
Final Answer:
Missing apiGroup in subjects causes permission failure. -> Option A
Quick Check:
Subjects need apiGroup for user binding [OK]
Hint: Always include apiGroup in subjects for users [OK]
Common Mistakes:
Omitting apiGroup in subjects
Confusing Role and ClusterRole in roleRef
Assuming namespace or user existence is the problem
5. You want to grant a service account named deploy-bot in namespace dev permission to create pods across all namespaces. Which is the correct approach?
hard
A. Create a RoleBinding in each namespace binding deploy-bot to a Role with pod creation rights.
B. Create a RoleBinding in the dev namespace binding deploy-bot to a Role with pod creation rights.
C. Create a ClusterRoleBinding binding the deploy-bot service account to a ClusterRole with pod creation rights.
D. Create a ClusterRole with pod creation rights but no binding is needed.
Solution
Step 1: Identify scope needed
Permission to create pods across all namespaces requires cluster-wide scope.
Step 2: Choose correct binding type
A ClusterRoleBinding is needed to bind the deploy-bot service account to a ClusterRole with pod creation rights cluster-wide.
Final Answer:
Create a ClusterRoleBinding for deploy-bot to a ClusterRole with pod creation rights. -> Option C