This page shows how to investigate problems related to the execution of Init Containers.
<pod-name>
and the Init Containers as <init-container-1>
and
<init-container-2>
.The Pod status will give you an overview of Init Container execution:
kubectl get pod <pod-name>
For example, a status of Init:1/2
indicates that one of two Init Containers
has completed successfully:
NAME READY STATUS RESTARTS AGE
<pod-name> 0/1 Init:1/2 0 7s
See Understanding Pod status for more examples of status values and their meanings.
You can see detailed information about Init Container execution by running:
kubectl describe pod <pod-name>
For example, a Pod with two Init Containers might show the following:
Init Containers:
<init-container-1>:
Container ID: ...
...
State: Terminated
Reason: Completed
Exit Code: 0
Started: ...
Finished: ...
Ready: True
Restart Count: 0
...
<init-container-2>:
Container ID: ...
...
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: ...
Finished: ...
Ready: False
Restart Count: 3
...
You can also access the Init Container statuses programmatically by reading the
pod.beta.kubernetes.io/init-container-status
annotation on the Pod:
kubectl get pod <pod-name> --template '{{index .metadata.annotations "pod.beta.kubernetes.io/init-container-statuses"}}'
This will return the same information as above, but in raw JSON format.
You can access logs for an Init Container by passing its Container name along with the Pod name:
kubectl logs <pod-name> -c <init-container-2>
If your Init Container runs a shell script, it helps to enable printing of
commands as they’re executed. For example, you can do this in Bash by running
set -x
at the beginning of the script.
A Pod status beginning with Init:
summarizes the status of Init Container
execution. The table below describes some example status values that you might
see while debugging Init Containers.
Status | Meaning |
---|---|
Init:N/M |
The Pod has M Init Containers, and N have completed so far. |
Init:Error |
An Init Container has failed to execute. |
Init:CrashLoopBackOff |
An Init Container has failed repeatedly. |
A Pod with status Pending
has not yet begun executing Init Containers.
A Pod with status PodInitializing
or Running
has already finished executing
Init Containers.