<p>I am trying to create PostgreSQL pods on k8s.
after the pod deploy when I use kubectl get pods I see out</p>
<pre><code>NAME            READY        STATUS        RESTARTS         AGE   

pgadmin         1/1           Running       5                  9m
postgres        1/1           Running       5                8m
</code></pre>
<p>however when I run kubectl get pods -o wide then I see this output</p>
<pre><code>pgadmin         0/1           CrashLoopBackOff         4    7m
postgres        0/1           CrashLoopBackOff         4     7  
</code></pre>
<p>I am not sure why I see 2 different output.
when I run kubectl logs pgadmin-63545-634536   I see the following output</p>
<pre><code>pgAdmin 4 - Application Initialisation
======================================

[2022-11-15 14:43:28 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2022-11-15 14:43:28 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
[2022-11-15 14:43:28 +0000] [1] [INFO] Using worker: gthread
[2022-11-15 14:43:28 +0000] [90] [INFO] Booting worker with pid: 90
[2022-11-15 14:44:24 +0000] [1] [INFO] Handling signal: term
[2022-11-15 14:44:25 +0000] [90] [INFO] Worker exiting (pid: 90)
[2022-11-15 14:44:26 +0000] [1] [INFO] Shutting down: Master


</code></pre>
<p>Can you please explain me what is this behavior and why my pods shutdown ?
I am very new to K8s.
Thanks in advance.</p>
<p>I try to inspect the log file</p>

<p>To answer why you are seeing two different outputs, you have to understand how a container runs in Kubernetes.</p>
<p>In docker, a container can run and then terminate, but then stay stopped unless you tell docker you want that container to automatically restart using the <code>--restart yes</code> switch</p>
<p>In a Kubernetes deployment (<a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/deployment/</a>), the <code>--restart yes</code> is implied -- namely, when a container (or &quot;pod&quot; in the Kubernetes world) exits, regardless of whether the exit was intentional or not, then Kubernetes will restart the container and will keep trying to restart it.</p>
<p>The exception to this is when you are running a <code>Job</code> (<a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/job/</a>) or <code>CronJob</code> (<a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/</a>), which will run and restart until they complete successfully and then terminate, but that is beyond the scope of your question.</p>
<p>You can see from the &quot;Restarts&quot; count in your output that the number of restarts is increasing. Kubernetes will attempt to restart the exited containers as described above, but if it detects that it is restarting it repeatedly, it will start to add a &quot;back off&quot; period (i.e. it will add a delay before it tries to restart the container) -- during this delay period, the status of the pod will be &quot;CrashLoopBackOff&quot;</p>
<p>To answer why this is happening, you should describe the pod using <code>kubectl describe</code>. For example:</p>
<pre><code>kubectl describe pod --namespace {name-of-namespace} pgadmin
</code></pre>
<p>This will give you details of the pod and look under the <code>Events</code> section -- it may have some details of what happened. Most likely the Liveness Probe (<a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/</a>) failed and therefore Kubernetes thinks the pods are dead, and restarts them accordingly.</p>
