Kubernetes and Cloud Native Associate (KCNA) — Question 14
Which is the correct kubectl command to display logs in real time?
Answer options
- A. kubectl logs -p test-container-1
- B. kubectl logs -c test-container-1
- C. kubectl logs -l test-container-1
- D. kubectl logs -f test-container-1
Correct answer: D
Explanation
The correct answer is D, as the '-f' flag allows you to follow log output in real-time. Option A uses '-p', which shows logs from the previous instance, while B uses '-c', which specifies the container name but does not indicate real-time logging. Option C uses '-l', which filters logs by label, but again does not provide real-time output.