Docker and Kubernetes

List pods, read their logs and delete a stuck one

The everyday kubectl commands: see your pods, read what they printed, find out why one crashed and restart it.

Fill these in once
  1. List the pods
    Terminal
    kubectl get pods

    Add -A to see pods in every namespace or -n followed by a name for just one.

  2. Read a pod's logs
    Terminal
    kubectl logs my-app-7d9c5b6f4-x2kqp
  3. Follow the logs live
    Terminal
    kubectl logs -f my-app-7d9c5b6f4-x2kqp

    Press Ctrl+C to stop.

  4. Read the logs from before it crashed
    Terminal
    kubectl logs my-app-7d9c5b6f4-x2kqp --previous

    Use this when the status says CrashLoopBackOff.

  5. See why a pod won't start
    Terminal
    kubectl describe pod my-app-7d9c5b6f4-x2kqp

    The Events list at the bottom usually says what went wrong.

  6. Delete a stuck pod
    Terminal
    kubectl delete pod my-app-7d9c5b6f4-x2kqp

    If a deployment made it, a fresh pod starts by itself.

Check it worked

  1. Check the new pod is running
    Terminal
    kubectl get pods
  1. List the pods
    Terminal · Ubuntu / Debian
    kubectl get pods

    Add -A to see pods in every namespace or -n followed by a name for just one.

  2. Read a pod's logs
    Terminal · Ubuntu / Debian
    kubectl logs my-app-7d9c5b6f4-x2kqp
  3. Follow the logs live
    Terminal · Ubuntu / Debian
    kubectl logs -f my-app-7d9c5b6f4-x2kqp

    Press Ctrl+C to stop.

  4. Read the logs from before it crashed
    Terminal · Ubuntu / Debian
    kubectl logs my-app-7d9c5b6f4-x2kqp --previous

    Use this when the status says CrashLoopBackOff.

  5. See why a pod won't start
    Terminal · Ubuntu / Debian
    kubectl describe pod my-app-7d9c5b6f4-x2kqp

    The Events list at the bottom usually says what went wrong.

  6. Delete a stuck pod
    Terminal · Ubuntu / Debian
    kubectl delete pod my-app-7d9c5b6f4-x2kqp

    If a deployment made it, a fresh pod starts by itself.

Check it worked

  1. Check the new pod is running
    Terminal · Ubuntu / Debian
    kubectl get pods
  1. List the pods
    PowerShell
    kubectl get pods

    Add -A to see pods in every namespace or -n followed by a name for just one.

  2. Read a pod's logs
    PowerShell
    kubectl logs my-app-7d9c5b6f4-x2kqp
  3. Follow the logs live
    PowerShell
    kubectl logs -f my-app-7d9c5b6f4-x2kqp

    Press Ctrl+C to stop.

  4. Read the logs from before it crashed
    PowerShell
    kubectl logs my-app-7d9c5b6f4-x2kqp --previous

    Use this when the status says CrashLoopBackOff.

  5. See why a pod won't start
    PowerShell
    kubectl describe pod my-app-7d9c5b6f4-x2kqp

    The Events list at the bottom usually says what went wrong.

  6. Delete a stuck pod
    PowerShell
    kubectl delete pod my-app-7d9c5b6f4-x2kqp

    If a deployment made it, a fresh pod starts by itself.

Check it worked

  1. Check the new pod is running
    PowerShell
    kubectl get pods

New to log? I explain it in plain English on Layman Terms.