nerdexam
Linux_Foundation

CKA · Question #28

Print pod name and start time to "/opt/pod-status" file

The task requires using kubectl with custom output columns to extract pod names and their start times, then redirecting this output to a specified file.

Submitted by asante_acc· May 4, 2026Workloads and Scheduling

Question

Print pod name and start time to "/opt/pod-status" file

Exhibits

CKA question #28 exhibit 1
CKA question #28 exhibit 2

Explanation

The task requires using kubectl with custom output columns to extract pod names and their start times, then redirecting this output to a specified file.

Approach. The correct interaction is to type a specific kubectl command into the terminal that retrieves the pod names and their exact start times, and then redirects this output to the /opt/pod-status file. The kubectl get pods command needs to be augmented with an output format that explicitly provides the name and startTime fields from the pod's metadata and status.

Here's the command to enter: kubectl get pods -o custom-columns=NAME:.metadata.name,START_TIME:.status.startTime > /opt/pod-status

Explanation:

  • kubectl get pods: This is the standard command to list all pods in the current namespace.
  • -o custom-columns=...: This flag allows specifying custom output columns. We define two columns:
    • NAME:.metadata.name: This creates a column named 'NAME' and populates it with the pod's name, found at .metadata.name in the pod object structure.
    • START_TIME:.status.startTime: This creates a column named 'START_TIME' and populates it with the pod's exact start timestamp, found at .status.startTime in the pod object structure. The AGE column shown in the default output is a relative duration, not the absolute start time.
  • > /opt/pod-status: This is a standard shell redirection operator that sends the entire output of the kubectl command to the specified file, /opt/pod-status.

Common mistakes.

  • common_mistake. Several common mistakes could lead to an incorrect answer:
  1. Using default kubectl get pods output: The default output only shows 'AGE' (e.g., '5h51m'), not the precise 'START_TIME' (e.g., '2023-10-27T10:00:00Z') which is required by the question. Simply running kubectl get pods > /opt/pod-status would be incorrect.
  2. Incorrect jsonpath or custom-columns syntax: Errors in specifying the JSONPath (e.g., NAME:.name, START_TIME:.startTime without the correct parent paths metadata and status) would result in missing or incorrect data.
  3. Forgetting output redirection: If the command is run without > /opt/pod-status, the output will just be printed to the terminal, failing to fulfill the requirement of writing to the file.
  4. Attempting to parse kubectl describe pod output: While kubectl describe pod <pod-name> contains the start time, it also provides a lot of other information and would require complex text processing (e.g., grep, awk) for each pod, which is inefficient and generally not the intended solution for such questions.

Concept tested. This question tests the candidate's knowledge of Kubernetes pod management, specifically using the kubectl command-line tool to retrieve detailed information about pods. Key concepts include:

  • kubectl get command: Basic usage for listing resources.
  • Output formatting: Using advanced output options like custom-columns (or jsonpath/go-template) to extract specific fields from Kubernetes object manifests.
  • Pod object structure: Understanding where metadata.name and status.startTime are located within a Pod's API object.
  • Shell redirection: Using > to direct command output to a file.

Topics

#kubectl#pods#jsonpath#output redirection

Community Discussion

No community discussion yet for this question.

Full CKA Practice