Skip to content

Kubernetes: Debug: describe, events, logs

8 Kubernetes commands: Debug: describe, events, logs. Click a command to see what each part does.

Index
8 items
Click a command to see what each part does.

Debug: describe, events, logs8

  • kubectl describe pod <pod> -n <namespace>Why is a pod not starting?

    What each part does

    1. describe pod <pod>status, conditions, container states (Last State / Exit Code) and events at the bottom
    2. -n <namespace>namespace of the pod

    Tip Look for ImagePullBackOff, FailedScheduling, OOMKilled, probe failures in Events.

  • kubectl get events -n <namespace> --sort-by=.metadata.creationTimestampRecent events, newest last

    What each part does

    1. get eventscluster events (scheduling, pulls, kills, probe failures)
    2. --sort-by=.metadata.creationTimestampoldest → newest
  • kubectl events -n <namespace> --types=WarningOnly warning events

    What each part does

    1. kubectl eventsnewer events subcommand
    2. --types=Warningonly Warning-type events
  • kubectl logs -f <pod> -n <namespace> --tail=200Follow logs of a pod

    What each part does

    1. logs <pod>container's stdout/stderr
    2. -fstream new lines
    3. --tail=200start from the last 200 lines
  • kubectl logs <pod> -c <container> --previousLogs of the crashed (previous) container

    What each part does

    1. -c <container>pick a container in a multi-container pod
    2. --previouslogs of the previous instance, i.e. the one that crashed
  • kubectl logs -l app=<app> --all-containers --prefix -fLogs from all pods with a label

    What each part does

    1. -l app=<app>every pod matching the label
    2. --all-containersall containers in each pod
    3. --prefixprefix lines with pod/container name
    4. -ffollow
  • kubectl logs deploy/<deployment> --since=1h | grep -i errorGrep logs for errors

    What each part does

    1. deploy/<deployment>logs from one pod of the deployment
    2. --since=1honly the last hour
    3. | grep -i errorkeep lines with "error", any case
  • kubectl top pod -n <namespace> --sort-by=memory --containersCPU / memory usage

    What each part does

    1. top podlive usage (needs metrics-server)
    2. --sort-by=memoryhighest memory first (or cpu)
    3. --containersper container instead of per pod

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…