Essential Commands
medium

Pregunta de Essential Commands #019e3a4f

Enunciado de la Pregunta
Essential Commands
#kubectl
#logs
#real-time
#kubernetes
Medio

Which is the correct kubectl command to display logs in real time?

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

Correcto

Explicación Oficial / Explicaciones de la Comunidad

The correct command to display logs in real time is kubectl logs -f test-container-1. The -f flag (short for --follow) streams the logs continuously, similar to tail -f.

How it Works

kubectl logs retrieves logs from a pod or container. The -f flag keeps the connection open and outputs new log lines as they are written. This is essential for debugging and monitoring live applications.

Why the Correct Value is Right

The -f flag is specifically designed for real-time log streaming. It is the standard way to follow logs in Kubernetes, analogous to tail -f in Linux.

Why the Incorrect Values are Wrong

  • The -p flag (short for --previous) prints logs from the previous instance of a container (e.g., after a restart), not real-time streaming.
  • The -c flag (short for --container) specifies a container name within a pod when multiple containers exist; it does not enable real-time output.
  • The -l flag (short for --selector) filters pods by label; it does not stream logs in real time.