It shows the logs (output messages) from the main container inside the specified pod. This helps to see what the application inside the pod is doing or if there are any errors.
Click to reveal answer
beginner
How do you view logs from a specific container in a pod with multiple containers?
Use kubectl logs <pod-name> -c <container-name> to get logs from the chosen container inside the pod.
Click to reveal answer
beginner
What option shows logs continuously as new lines are added?
The -f or --follow option streams the logs live, like watching a live feed. Example: kubectl logs -f <pod-name>.
Click to reveal answer
intermediate
How can you get logs from previous instances of a container that crashed?
Use kubectl logs <pod-name> -c <container-name> --previous to see logs from the last terminated container.
Click to reveal answer
beginner
Why is kubectl logs useful for debugging?
It helps you see what is happening inside your app running in Kubernetes. You can find errors, warnings, or understand app behavior without accessing the pod directly.
Click to reveal answer
Which command streams logs live from a pod?
Akubectl get pods
Bkubectl exec pod-name
Ckubectl describe pod pod-name
Dkubectl logs -f pod-name
✗ Incorrect
The -f option in kubectl logs streams logs live as they are generated.
How do you get logs from a specific container in a pod?
Akubectl logs pod-name -c container-name
Bkubectl logs pod-name --all-containers
Ckubectl get logs container-name
Dkubectl describe container container-name
✗ Incorrect
The -c option specifies the container name inside the pod for logs.
What does the --previous flag do in kubectl logs?
AShows logs from all containers
BShows logs from the last terminated container
CShows logs from the current running container
DRestarts the pod
✗ Incorrect
The --previous flag shows logs from the container instance before it crashed or restarted.
Which command is NOT used to view logs?
Akubectl describe pod pod-name
Bkubectl logs pod-name -f
Ckubectl logs pod-name
Dkubectl logs pod-name -c container-name
✗ Incorrect
kubectl describe shows pod details but not logs.
Why use kubectl logs for debugging?
ATo create new pods
BTo delete pods
CTo see app output and errors inside pods
DTo update Kubernetes version
✗ Incorrect
kubectl logs helps check what the app inside the pod is doing or if it has errors.
Explain how to use kubectl logs to debug a pod with multiple containers.
Think about how to target one container inside a pod.
You got /3 concepts.
Describe how to view logs from a crashed container to find out what went wrong.
Look for logs from the last terminated container.
You got /3 concepts.
Practice
(1/5)
1. What does the kubectl logs command do in Kubernetes?
easy
A. Deletes a pod from the cluster
B. Lists all pods running in the cluster
C. Creates a new pod with specified configuration
D. Shows the output logs of a container inside a pod
Solution
Step 1: Understand the purpose of kubectl logs
This command is used to view the logs generated by containers running inside pods in Kubernetes.
Step 2: Differentiate from other commands
Deleting pods uses kubectl delete, creating pods uses kubectl create, and listing pods uses kubectl get pods. None of these show logs.
Final Answer:
Shows the output logs of a container inside a pod -> Option D
Quick Check:
Logs = Output from container [OK]
Hint: Logs show container output, not pod creation or deletion [OK]
Common Mistakes:
Confusing logs with pod creation or deletion
Thinking logs list pods instead of showing output
Assuming logs show cluster-wide events
2. Which of the following is the correct syntax to follow logs live from a pod named webapp-123?
easy
A. kubectl logs webapp-123 --follow
B. kubectl logs --tail webapp-123
C. kubectl logs webapp-123 -t
D. kubectl logs -t webapp-123
Solution
Step 1: Recall correct flag placement
The --follow flag comes after the pod name in the kubectl logs command syntax.
Step 2: Check distractor flags
Distractors use --tail (shows last lines, no streaming) or -t (timestamps, no follow). Only --follow streams live.
Final Answer:
kubectl logs webapp-123 --follow -> Option A
Quick Check:
Pod name first, then flags [OK]
Hint: Put pod name before flags like --follow [OK]
Common Mistakes:
Placing flags before pod name
Using --tail or -t instead of --follow
Mixing order of arguments
3. Given the command kubectl logs mypod --tail=5, what will be the output?
medium
A. Shows all logs except the last 5 lines from the pod named mypod
B. Shows the first 5 lines of logs from the pod named mypod
C. Shows the last 5 lines of logs from the pod named mypod
D. Shows logs only if the pod has more than 5 containers
Solution
Step 1: Understand the --tail option
The --tail=5 option limits the output to the last 5 lines of the logs.
Step 2: Confirm it applies to the specified pod
The command targets the pod named mypod, so logs shown are from that pod only.
Final Answer:
Shows the last 5 lines of logs from the pod named mypod -> Option C
Quick Check:
--tail = last lines [OK]
Hint: --tail shows last lines, not first [OK]
Common Mistakes:
Thinking --tail shows first lines
Confusing pod logs with container logs
Assuming it filters by container count
4. You run kubectl logs mypod -c mycontainer but get an error saying container not found. What is the likely cause?
medium
A. The pod mypod is not running
B. The container name mycontainer does not exist in pod mypod
C. You forgot to add the --follow flag
D. The pod mypod has multiple containers but you did not specify one
Solution
Step 1: Analyze the error message
The error says container not found, which means the container name given is incorrect or missing in the pod.
Step 2: Check command correctness
You specified -c mycontainer, so if the container name is wrong, the error appears. Pod running state or missing --follow flag does not cause this error.
Final Answer:
The container name mycontainer does not exist in pod mypod -> Option B
Quick Check:
Container name must match exactly [OK]
Hint: Check container name spelling matches pod's containers [OK]
Common Mistakes:
Assuming pod state causes container not found error
Forgetting to specify container when multiple exist
Using wrong flag for container name
5. You want to debug a pod with two containers named frontend and backend. Which command correctly streams live logs from the backend container only?
hard
A. kubectl logs podname -c backend --follow
B. kubectl logs podname --tail -c backend
C. kubectl logs -c backend podname --tail
D. kubectl logs --tail podname -c backend
Solution
Step 1: Recall correct argument order
The pod name must come immediately after kubectl logs, followed by flags like -c and --follow.
Step 2: Confirm container and follow flag usage
Using -c backend specifies the backend container, and --follow streams logs live.
Final Answer:
kubectl logs podname -c backend --follow -> Option A
Quick Check:
Pod name first, then container and flags [OK]
Hint: Pod name first, then container (-c) and --follow [OK]
Common Mistakes:
Placing flags before pod name
Mixing order of container and follow flags
Using unsupported shorthand flags
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.