KCNA ยท Application delivery and debugging
Debugging with kubectl
logs, describe, exec, events, port-forward, kubectl debug and ephemeral containers.
Key points
- Start wide, then narrow: kubectl get pods shows status, kubectl describe pod shows events (scheduling, image pulls, probe failures), kubectl logs shows container output, kubectl exec runs a command inside a container, and kubectl port-forward reaches a Pod or Service from your machine.
- When the image has no shell, kubectl debug adds an ephemeral container to the running Pod, or makes a modified copy with --copy-to.
Source: https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/
Practice questions
Which command shows a Pod's events, such as failed image pulls or scheduling problems?
- kubectl describe pod
- kubectl top node
- kubectl config view
- kubectl api-resources
Show answer
Answer: A. kubectl describe pod
describe includes an Events section for the object. The others show resource usage, kubeconfig and API types.
Which commands help you look at a running Pod?
- kubectl logs
- kubectl exec
- kubectl port-forward
- kubectl cordon
- kubectl taint nodes
Show answer
Answer: A. kubectl logs, B. kubectl exec, C. kubectl port-forward
Logs, exec and port-forward all inspect or reach a Pod. cordon and taint affect node scheduling, not Pod internals.
True or false: adding an ephemeral debug container with kubectl debug requires restarting the target Pod.
Show answer
Answer: False
Ephemeral containers are added to an already running Pod, so it keeps running. Only --copy-to creates a different Pod.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
