D. apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
Solution
Step 1: Check apiVersion and kind for Role
The correct apiVersion for RBAC Role is "rbac.authorization.k8s.io/v1" and kind is "Role".
Step 2: Verify metadata and rules structure
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"] correctly defines metadata and rules for a Role to access pods with verbs get, watch, list.
Final Answer:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"] -> Option D
Quick Check:
Role uses rbac.authorization.k8s.io/v1 and kind Role [OK]
Hint: Role uses rbac.authorization.k8s.io/v1 and kind Role exactly [OK]
Common Mistakes:
Using wrong apiVersion like v1 instead of rbac.authorization.k8s.io/v1
Confusing Role with RoleBinding or ClusterRole
Mixing Role and ClusterRole in the same definition
3. Given this RoleBinding YAML snippet, what does it do?
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
subjects:
- kind: User
name: alice
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
medium
A. Revokes all permissions from user 'alice'
B. Grants user 'alice' permission to create pods cluster-wide
C. Grants user 'alice' permission to read pods in the namespace
D. Binds user 'alice' to a ClusterRole named pod-reader
Solution
Step 1: Analyze RoleBinding components
The RoleBinding binds a Role named 'pod-reader' to user 'alice' in the current namespace.
Step 2: Understand Role permissions
The Role 'pod-reader' typically allows reading pods (get, watch, list) in the namespace.
Final Answer:
Grants user 'alice' permission to read pods in the namespace -> Option C
Quick Check:
RoleBinding + Role = namespace-scoped permission [OK]
Hint: RoleBinding links Role permissions to a user in a namespace [OK]
Common Mistakes:
Confusing RoleBinding with ClusterRoleBinding
Assuming permissions are cluster-wide
Thinking it revokes permissions
4. You created a RoleBinding but the user still cannot access pods. What is the most likely cause?
medium
A. The RoleBinding references a Role that does not exist
B. The user is not logged into the cluster
C. The RoleBinding is missing the apiVersion field
D. The RoleBinding uses ClusterRole instead of Role
Solution
Step 1: Check RoleBinding references
If the RoleBinding points to a Role that does not exist, permissions won't apply.
Step 2: Verify Role existence
Without the referenced Role, Kubernetes cannot grant permissions, causing access failure.
Final Answer:
The RoleBinding references a Role that does not exist -> Option A
Quick Check:
RoleBinding must reference an existing Role [OK]
Hint: Always verify Role exists before binding [OK]
Common Mistakes:
Ignoring Role existence and blaming user login
Assuming missing apiVersion causes access denial
Confusing Role with ClusterRole in RoleBinding
5. You want to allow a service account to manage deployments across all namespaces securely. Which RBAC setup is best?
hard
A. Create a ClusterRole with deployment permissions and bind it with a ClusterRoleBinding to the service account
B. Create a Role with deployment permissions in each namespace and bind it with RoleBindings
C. Create a RoleBinding with cluster-wide scope to the service account
D. Assign admin cluster role directly to the service account
Solution
Step 1: Understand scope of permissions needed
Managing deployments across all namespaces requires cluster-wide permissions.
Step 2: Choose appropriate RBAC objects
ClusterRole defines permissions cluster-wide; ClusterRoleBinding assigns it to the service account.
Step 3: Avoid less secure or inefficient options
Creating Roles per namespace is tedious; RoleBinding cannot grant cluster-wide scope; admin role is too broad.
Final Answer:
Create a ClusterRole with deployment permissions and bind it with a ClusterRoleBinding to the service account -> Option A