<p>How to debug why it's status is CrashLoopBackOff?</p>

<p>I am not using minikube , working on Aws Kubernetes instance.</p>

<p>I followed this tutorial.
<a href="https://github.com/mkjelland/spring-boot-postgres-on-k8s-sample" rel="nofollow noreferrer">https://github.com/mkjelland/spring-boot-postgres-on-k8s-sample</a></p>

<p>When I do </p>

<pre><code>  kubectl create -f specs/spring-boot-app.yml
</code></pre>

<p>and check status by </p>

<pre><code>  kubectl get pods 
</code></pre>

<p>it gives </p>

<pre><code>     spring-boot-postgres-sample-67f9cbc8c-qnkzg   0/1     CrashLoopBackOff   14         50m
</code></pre>

<p>Below Command </p>

<pre><code> kubectl describe pods spring-boot-postgres-sample-67f9cbc8c-qnkzg
</code></pre>

<p>gives </p>

<pre><code>Events:
  Type     Reason   Age                    From                      Message
  ----     ------   ----                   ----                      -------
  Warning  BackOff  3m18s (x350 over 78m)  kubelet, ip-172-31-11-87  Back-off restarting failed container
</code></pre>

<p>Command <strong>kubectl get pods --all-namespaces</strong> gives </p>

<pre><code>NAMESPACE     NAME                                           READY   STATUS             RESTARTS   AGE
default       constraintpod                                  1/1     Running            1          88d
default       postgres-78f78bfbfc-72bgf                      1/1     Running            0          109m
default       rcsise-krbxg                                   1/1     Running            1          87d
default       spring-boot-postgres-sample-667f87cf4c-858rx   0/1     CrashLoopBackOff   4          110s
default       twocontainers                                  2/2     Running            479        89d
kube-system   coredns-86c58d9df4-kr4zj                       1/1     Running            1          89d
kube-system   coredns-86c58d9df4-qqq2p                       1/1     Running            1          89d
kube-system   etcd-ip-172-31-6-149                           1/1     Running            8          89d
kube-system   kube-apiserver-ip-172-31-6-149                 1/1     Running            1          89d
kube-system   kube-controller-manager-ip-172-31-6-149        1/1     Running            1          89d
kube-system   kube-flannel-ds-amd64-4h4x7                    1/1     Running            1          89d
kube-system   kube-flannel-ds-amd64-fcvf2                    1/1     Running            1          89d
kube-system   kube-proxy-5sgjb                               1/1     Running            1          89d
kube-system   kube-proxy-hd7tr                               1/1     Running            1          89d
kube-system   kube-scheduler-ip-172-31-6-149                 1/1     Running            1          89d
</code></pre>

<p>Command <strong>kubectl logs spring-boot-postgres-sample-667f87cf4c-858rx</strong>
doesn't print anything.</p>

<p>First of all I fixed by postgres deployment, there was some error of "pod has unbound PersistentVolumeClaims" , so i fixed that error by this post 
<a href="https://stackoverflow.com/questions/52668938/pod-has-unbound-persistentvolumeclaims">pod has unbound PersistentVolumeClaims</a></p>

<p>So now my postgres deployment is running. </p>

<p><strong>kubectl logs spring-boot-postgres-sample-67f9cbc8c-qnkzg</strong> doesn't print anything, it means there is something wrong in config file.
<strong>kubectl describe pod spring-boot-postgres-sample-67f9cbc8c-qnkzg</strong> stating that container is terminated and reason is completed,
I fixed it by running container infinity time
by adding </p>

<pre><code>   # Just sleep forever
command: [ "sleep" ]
args: [ "infinity" ]
</code></pre>

<p>So now my deployment is running.
But now i Exposed my service by </p>

<pre><code>kubectl expose deployment spring-boot-postgres-sample --type=LoadBalancer --port=8080
</code></pre>

<p>but can't able to get External-Ip , so I did </p>

<pre><code>kubectl patch svc &lt;svc-name&gt; -n &lt;namespace&gt; -p '{"spec": {"type": "LoadBalancer", "externalIPs":["172.31.71.218"]}}'
</code></pre>

<p>So I get my external-Ip as "172.31.71.218"</p>

<p>But now the problem is curl <a href="http://172.31.71.218:8080/" rel="nofollow noreferrer">http://172.31.71.218:8080/</a> getting timeout</p>

<p>Anything i did wrong?</p>

<p>Here is my deployment.yml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: spring-boot-postgres-sample
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      name: spring-boot-postgres-sample
      labels:
        app: spring-boot-postgres-sample
    spec:
      containers:
      - name: spring-boot-postgres-sample
        command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]
        env:
          - name: POSTGRES_USER
            valueFrom:
              configMapKeyRef:
                name: postgres-config
                key: postgres_user
          - name: POSTGRES_PASSWORD
            valueFrom:
              configMapKeyRef:
                name: postgres-config
                key: postgres_password
          - name: POSTGRES_HOST
            valueFrom:
              configMapKeyRef:
                name: hostname-config
                key: postgres_host
        image: &lt;mydockerHUbaccount&gt;/spring-boot-postgres-on-k8s:v1
</code></pre>

<p>Here is my postgres.yml</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  namespace: default
data:
  postgres_user: postgresuser
  postgres_password: password
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  template:
    metadata:
      labels:
        app: postgres
    spec:
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: postgres-pv-claim
      containers:
        - image: postgres
          name: postgres
          env:
            - name: POSTGRES_USER
              valueFrom:
                configMapKeyRef:
                  name: postgres-config
                  key: postgres_user
            - name: POSTGRES_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: postgres-config
                  key: postgres_password
            - name: PGDATA
              value: /var/lib/postgresql/data/pgdata
          ports:
            - containerPort: 5432
              name: postgres
          volumeMounts:
            - name: postgres-storage
              mountPath: /var/lib/postgresql/data
---
apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  type: ClusterIP
  ports:
    - port: 5432
  selector:
    app: postgres
</code></pre>

<p>Here How i got host-config map</p>

<pre><code>kubectl create configmap hostname-config --from-literal=postgres_host=$(kubectl get svc postgres -o jsonpath="{.spec.clusterIP}")
</code></pre>
