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
.
- You should be familiar with the basics of .
- You should have Configured an Init Container.
Display the status of your pod:
NAME READY STATUS RESTARTS AGE
<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:
<init-container-1>:
Container ID: ...
...
State: Terminated
Reason: Completed
Exit Code: 0
Finished: ...
Ready: True
Restart Count: 0
...
Container ID: ...
...
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: ...
Ready: False
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.
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)