Question 28
Domain 5: TroubleshootingWhich kubectl command monitors pod loggy’s logs, filters for lines containing `issue-not-found`, and writes the matching output to `/tmp/pod.txt`?
Correct answer: A
Explanation
`kubectl logs -f loggy` streams pod loggy’s logs in follow mode, and `grep 'issue-not-found'` filters only lines containing that text. The `>` redirection writes the matching output to `/tmp/pod.txt`, matching the command shown: `kubectl logs -f loggy | grep 'issue-not-found' > /tmp/pod.txt`.
Why each option is right or wrong
A. kubectl logs -f loggy | grep 'issue-not-found' > /tmp/pod.txt
Under the `kubectl logs` command syntax, `-f` (or `--follow`) streams the pod’s log output continuously, so it is the correct flag when the question asks to monitor logs in real time. Piping that stream into `grep 'issue-not-found'` restricts the output to lines containing that exact string, and the shell redirection operator `>` sends the filtered results into `/tmp/pod.txt` rather than displaying them on screen.
B. kubectl exec loggy -- grep 'issue-not-found' /var/log/pod.txt > /tmp/pod.txt
C. kubectl get logs loggy | grep 'issue-not-found' > /tmp/pod.txt
D. kubectl describe pod loggy | grep 'issue-not-found' > /tmp/pod.txt