Bitzu

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

Single choice

Which command shows a Pod's events, such as failed image pulls or scheduling problems?

  1. kubectl describe pod
  2. kubectl top node
  3. kubectl config view
  4. 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.

Select all that apply

Which commands help you look at a running Pod?

  1. kubectl logs
  2. kubectl exec
  3. kubectl port-forward
  4. kubectl cordon
  5. 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

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.

Download on the App StoreGet it on Google Play

More KCNA topics in this module