Courseiva

How to Create a Kubernetes Role for Listing Pods in a Specific Namespace

A developer needs to create a Role that allows listing pods in the 'dev' namespace. Which YAML snippet correctly defines this Role?

Quick Answer

The correct answer is the YAML snippet that defines a Role with apiVersion: rbac.authorization.k8s.io/v1, kind: Role, metadata including namespace: dev, and rules specifying apiGroups: [""], resources: ["pods"], and verbs: ["list"]. This is correct because a Role in Kubernetes RBAC is namespace-scoped, meaning it only grants permissions within the namespace specified in its metadata, and the empty apiGroups string [""] targets the core API group where pods reside. On the CKA exam, this question tests your ability to distinguish between a Role and a ClusterRole—a common trap is using a ClusterRole when the requirement explicitly limits access to a single namespace. Remember that if the task says "in a specific namespace," you must use a Role, not a ClusterRole, and always include the namespace field. A helpful memory tip: "Role is for a single namespace, ClusterRole is for the whole cluster—when listing pods in dev, keep your Role confined."

⚠ Common exam trap

Many candidates confuse 'get' with 'list' or choose a ClusterRole thinking it can be used for namespace-scoped access, but the CKA exam tests precise understanding that a Role must be namespace-scoped and use the correct verb for the intended operation.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: pod-lister namespace: dev rules: - apiGroups: [""] resources: ["pods"] verbs: ["list"]

It defines a Role (not ClusterRole) scoped to the 'dev' namespace with the 'list' verb on 'pods', which matches the requirement exactly. In Kubernetes RBAC, a Role grants permissions within a specific namespace, and the empty apiGroups string [""] refers to the core API group where pods reside.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: pod-lister rules: - apiGroups: [""] resources: ["pods"] verbs: ["list"]

    Why it's wrong here

    ClusterRole is cluster-scoped; a Role should be used for namespace-scoped permissions.

  • apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: pod-lister-binding namespace: dev subjects: - kind: User name: dev-user roleRef: kind: Role name: pod-lister apiGroup: rbac.authorization.k8s.io

    Why it's wrong here

    This is a RoleBinding, not a Role.

  • apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: pod-lister namespace: dev rules: - apiGroups: [""] resources: ["pods"] verbs: ["list"]

    Why this is correct

    This defines a Role in the dev namespace with list pods permission.

  • apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: pod-lister rules: - apiGroups: [""] resources: ["pods"] verbs: ["get"]

    Why it's wrong here

    The verb 'list' is required, not 'get'.

Quick reference

Access Control Model Comparison

ModelAcronymWho Controls Access?Best For
Discretionary Access ControlDACResource ownerSmall teams, file shares
Mandatory Access ControlMACSystem / security labelsClassified govt / military
Role-Based Access ControlRBACAdministrator (via roles)Enterprise environments
Attribute-Based Access ControlABACPolicy engine (user + resource attributes)Fine-grained, dynamic policies
Rule-Based Access ControlRuBACSystem rules / ACLsFirewall rules, network ACLs

About these practice questions

Courseiva writes every CKA question from scratch — 302 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on CKA

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. You are applying the following RBAC manifest: --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: development name: pod-reader rules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "watch", "list"] Which TWO statements are true about this Role? (Choose TWO.)

medium
  • A.It also grants access to secrets in the 'development' namespace
  • B.It allows reading pod details in the 'development' namespace
  • C.It grants permissions across all namespaces
  • D.It grants permissions only within the 'development' namespace
  • E.It allows creating pods in the 'development' namespace

Why B: The Role explicitly defines rules for the 'pods' resource with verbs 'get', 'watch', and 'list' in the 'development' namespace. These verbs allow reading pod details such as their specifications, status, and metadata. The Role is scoped to the 'development' namespace, so it only grants these read permissions within that namespace.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CKA practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKA exam.