Debug Init Containers

    You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as control plane hosts. If you do not already have a cluster, you can create one by using minikube or you can use one of these Kubernetes playgrounds:

    To check the version, enter kubectl version.

    Display the status of your pod:

    1. NAME READY STATUS RESTARTS AGE
    2. <pod-name> 0/1 Init:1/2 0 7s

    See for more examples of status values and their meanings.

    View more detailed information about Init Container execution:

    For example, a Pod with two Init Containers might show the following:

    1. <init-container-1>:
    2. Container ID: ...
    3. ...
    4. State: Terminated
    5. Reason: Completed
    6. Exit Code: 0
    7. Finished: ...
    8. Ready: True
    9. Restart Count: 0
    10. ...
    11. Container ID: ...
    12. ...
    13. State: Waiting
    14. Reason: CrashLoopBackOff
    15. Last State: Terminated
    16. Reason: Error
    17. Exit Code: 1
    18. Started: ...
    19. Ready: False
    20. Restart Count: 3

    This command will return the same information as above in raw JSON.

    Pass the Init Container name along with the Pod name to access its logs.

    1. kubectl logs <pod-name> -c <init-container-2>

    Init Containers that run a shell script print commands as they’re executed. For example, you can do this in Bash by running set -x at the beginning of the script.

    Last modified April 26, 2022 at 12:30 AM PST: Reorg the monitoring task section (#32823) (f26e8eff2)