0
0
Kubernetesdevops~5 mins

kubectl logs for debugging in Kubernetes - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the command kubectl logs <pod-name> do?
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
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
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
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
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
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.