You have a pod named webapp-1234 with two containers: frontend and backend. Which kubectl logs command will show logs only from the backend container?
Use the -c or --container flag to specify the container name.
The kubectl logs command with -c backend fetches logs from the backend container inside the pod webapp-1234. Option C will fail because the pod has multiple containers and no container is specified, Option C fetches logs from the frontend container, and C tries to get logs from a pod named backend which does not exist.
A pod restarted due to a crash. You want to see the logs from the previous container instance to understand what caused the crash. Which command will show those logs?
Look for a flag that fetches logs from the last terminated container.
The --previous flag shows logs from the previous container instance before it restarted. --all-containers is not a valid flag for kubectl logs, --follow streams live logs, and --timestamps adds timestamps to logs.
You want to fetch logs from a pod named api-server but only want to see logs starting from a specific time, for example, logs after 10 minutes ago. Which approach is correct?
Check the flag that filters logs by duration from now.
The --since=10m flag fetches logs from the last 10 minutes. --since-time requires a full timestamp, --tail limits number of lines, and --from-time is not a valid flag.
You run kubectl logs mypod but get the error: Error from server (BadRequest): a container name must be specified for pod "mypod". What is the most likely cause?
Check if the pod has more than one container and if the command specifies which container.
This error happens when the pod has multiple containers and you do not specify which container's logs to fetch. Adding -c container-name fixes this. Option B would give a different "NotFound" error. --all-containers is not a valid flag for kubectl logs. Option B is unrelated as logs can be fetched from terminated pods.
You have a pod db-pod with two containers: db and sidecar. The pod keeps restarting. You want to check the logs of the previous instance of the db container only. What is the correct command sequence?
Combine container selection and previous logs flags.
To get logs from the previous instance of a specific container, you must specify both the container name with -c and the --previous flag. Option A selects the wrong container, Option A misses the container name, and D shows current logs only.