Sometimes a the pods gets a "CrashLoopBackOff" status as we can see below:
When an application inside a pod uses too much resources for example, the pod is stopped and it gets restarted by kubernetes over and over again. It happens because the "restart policy" of the pod is set to "Always" or "OnFailure" as we can see in the Yaml configuration file below:
kubernetes will try to restart the "crashing" pod, increasing the delay between the restarts, and you will see "CrashLoopbackOff" status when executing the "kubectl get pods" command. To investigate the reason behind the "CrashLoopbackOff" status, we can use the below command:
We see that the container inside the Pod has completed with a successful exit code : 0, but we notice that the run cycle of the Pod is short and kubernetes keeps restarting the pod over and over again, as we can see from the "Restart Count :539".
To avoid that we could execute a command in the Pod that will keep it from exiting as below, in the Yaml configuration file: