nerdexam
Linux_Foundation

CKA · Question #10

Create a file: /opt/KUCC0302/kucc0302.txt that lists all pods that implement service baz in namespace development. The format of the file should be one pod name per line.

CKA Exam: Finding Pods Behind a Service Overall Goal A Kubernetes Service routes traffic to pods using label selectors. The task is to identify which pods match the selector of the baz service in the development namespace, then write those pod names to a file. This tests your…

Submitted by obi.ng· May 4, 2026Services & Networking

Question

Create a file: /opt/KUCC0302/kucc0302.txt that lists all pods that implement service baz in namespace development. The format of the file should be one pod name per line.

Exhibit

CKA question #10 exhibit

Explanation

CKA Exam: Finding Pods Behind a Service

Overall Goal

A Kubernetes Service routes traffic to pods using label selectors. The task is to identify which pods match the selector of the baz service in the development namespace, then write those pod names to a file. This tests your ability to trace the relationship between Services and their backing Pods.


Step-by-Step Breakdown

Step 1: Inspect the service to find its selector

kubectl get service baz -n development -o yaml
# or more targeted:
kubectl get service baz -n development -o jsonpath='{.spec.selector}'

Why: A Service doesn't "contain" pods - it selects them via label selectors (e.g., app=baz). You must know the selector before you can find the pods. Skipping this means you're guessing which pods qualify.


Step 2: Find pods matching that selector

kubectl get pods -n development -l app=baz --no-headers -o custom-columns=":metadata.name"

Why: This filters pods by the exact label selector from Step 1. Using -l ensures you only get pods the service actually routes to. --no-headers and custom-columns strip formatting so the output is clean pod names - one per line, as required.

If the selector had multiple labels (e.g., app=baz,tier=frontend), you'd include all of them in -l.


Step 3: Write the output to the file

kubectl get pods -n development -l app=baz --no-headers -o custom-columns=":metadata.name" \
  > /opt/KUCC0302/kucc0302.txt

Why: The > redirect creates/overwrites the file with exactly the required format. The directory /opt/KUCC0302/ must already exist - if it doesn't, the redirect will fail. You can verify with cat /opt/KUCC0302/kucc0302.txt.


What Goes Wrong if Steps Are Skipped

MistakeConsequence
Skip Step 1, guess the labelWrong pods in the file - or no pods at all
Forget -n developmentSearches the wrong namespace, finds nothing
Include header row in outputFile format is wrong (first line is "NAME", not a pod name)
Miss one label from a multi-label selectorOverly broad results - pods that aren't actually targeted

Memory Tip

"Service → Selector → Pods" A Service is just a pointer. Follow the pointer (selector) to find what it points at (pods). kubectl describe service baz also shows the selector and the Endpoints list directly - a quick sanity check.

Topics

#kubectl#services#pods#label selectors

Community Discussion

No community discussion yet for this question.

Full CKA Practice