<p>From time to time all my pods restart and I'm not sure how to figure out why it's happening. Is there someplace in google cloud where I can get that information? or a kubectl command to run? It happens every couple of months or so. maybe less frequently than that.</p>

<p>Using below methods for checking the reason for pod restart:</p>
<p>Use <code>kubectl describe deployment &lt;deployment_name&gt;</code> and <code>kubectl describe pod &lt;pod_name&gt;</code> which contains the information.</p>
<pre><code># Events:
#   Type     Reason   Age                 From               Message
#   ----     ------   ----                ----               -------
#   Warning  BackOff  40m                 kubelet, gke-xx    Back-off restarting failed container
# ..
</code></pre>
<p>You can see that the pod is restarted due to image pull backoff. We need to troubleshoot on that particular issue.</p>
<p>Check for logs using :  <code>kubectl logs &lt;pod_name&gt;</code></p>
<p>To get previous logs of your container (the restarted one), you may use --previous key on pod, like this:</p>
<pre><code>kubectl logs your_pod_name --previous
</code></pre>
<p>You can also write a final message to /dev/termination-log, and this will show up as described in <a href="https://kubernetes.io/docs/tasks/debug/debug-application/determine-reason-pod-failure/#:%7E:text=Termination%20messages%20provide%20a%20way,to%20the%20general%20Kubernetes%20logs." rel="nofollow noreferrer">docs</a>.</p>
<p>Attaching a <a href="https://cloud.google.com/kubernetes-engine/docs/troubleshooting" rel="nofollow noreferrer">troubleshooting</a> doc for reference.</p>
