KCNA · Question #1
Which is the correct kubectl command to display logs in real time?
The correct answer is D. kubectl logs -f test-container-1. The kubectl logs command with the -f flag is used to stream logs from a container in real-time, similar to tail -f.
Question
Which is the correct kubectl command to display logs in real time?
Options
- Akubectl logs -p test-container-1
- Bkubectl logs -c test-container-1
- Ckubectl logs -l test-container-1
- Dkubectl logs -f test-container-1
How the community answered
(36 responses)- A3% (1)
- B3% (1)
- C6% (2)
- D89% (32)
Why each option
The `kubectl logs` command with the `-f` flag is used to stream logs from a container in real-time, similar to `tail -f`.
The `-p` or `--previous` flag displays logs from a previous instantiation of a container, not real-time logs.
The `-c` or `--container` flag specifies a container name when a Pod has multiple containers, but it doesn't enable real-time following.
The `-l` or `--selector` flag filters Pods based on a label selector, it does not relate to real-time log following.
The `-f` or `--follow` flag for `kubectl logs` specifically enables following the log output in real-time, continuously streaming new log entries as they are generated by the container. This is essential for monitoring live application behavior and debugging issues as they occur.
Concept tested: kubectl logs command options
Source: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs
Topics
Community Discussion
No community discussion yet for this question.