KCNA · Question #56
Which of the following will view the snapshot of previously terminated ruby container logs from Pod web-1?
The correct answer is A. kubectl logs -p -c ruby web-1. To view logs from a previously terminated container within a Kubernetes Pod, use kubectl logs with the -p (previous) flag and specify the container with -c.
Question
Which of the following will view the snapshot of previously terminated ruby container logs from Pod web-1?
Options
- Akubectl logs -p -c ruby web-1
- Ckubectl logs -p ruby web-1
- Dkubectl logs -p -c web-1 ruby
How the community answered
(62 responses)- A94% (58)
- C2% (1)
- D5% (3)
Why each option
To view logs from a previously terminated container within a Kubernetes Pod, use `kubectl logs` with the `-p` (previous) flag and specify the container with `-c`.
The `kubectl logs` command with the `-p` (or `--previous`) flag is used to retrieve logs from a previous instantiation of a container. The `-c` (or `--container`) flag specifies the container name within the Pod from which to retrieve logs, and `web-1` is the Pod name.
This command is missing the `-c` flag to specify the container name. `ruby` would be interpreted as part of the Pod name or an invalid argument without `-c`.
The order of arguments is incorrect; the container name (`ruby`) should follow the `-c` flag, and the Pod name (`web-1`) should be the primary argument.
Concept tested: `kubectl logs` previous container
Source: https://kubernetes.io/docs/reference/kubectl/cheatsheet/#viewing-finding-resources
Topics
Community Discussion
No community discussion yet for this question.