app nodejs in kubernetes cluster dont stay runing - CrashLoopBackOff

3/8/2019

I have a small application in nodejs to do tests with kubernetes, but it seems that the application does not keep running

I put all the code that I developed to test, in the GitHub

I'm run kubectl create -f deploy.yaml Works, but..

[webapp@srvapih ex-node]$ kubectl get pods
NAME                   READY   STATUS              RESTARTS   AGE
api-7b89bd4755-4lc6k   1/1     Running             0          5s
api-7b89bd4755-7x964   0/1     ContainerCreating   0          5s
api-7b89bd4755-dv299   1/1     Running             0          5s
api-7b89bd4755-w6tzj   0/1     ContainerCreating   0          5s
api-7b89bd4755-xnm8l   0/1     ContainerCreating   0          5s
[webapp@srvapih ex-node]$ kubectl get pods
NAME                   READY   STATUS             RESTARTS   AGE
api-7b89bd4755-4lc6k   0/1     CrashLoopBackOff   1          11s
api-7b89bd4755-7x964   0/1     CrashLoopBackOff   1          11s
api-7b89bd4755-dv299   0/1     CrashLoopBackOff   1          11s
api-7b89bd4755-w6tzj   0/1     CrashLoopBackOff   1          11s
api-7b89bd4755-xnm8l   0/1     CrashLoopBackOff   1          11s

Events for describe pod

Events:
  Type     Reason     Age                    From                                 Message
  ----     ------     ----                   ----                                 -------
  Normal   Pulled     6m48s (x5 over 8m14s)  kubelet, srvweb05.beirario.intranet  Container image "node:8-alpine" already present on machine
  Normal   Created    6m48s (x5 over 8m14s)  kubelet, srvweb05.beirario.intranet  Created container
  Normal   Started    6m48s (x5 over 8m12s)  kubelet, srvweb05.beirario.intranet  Started container
  Normal   Scheduled  6m9s                   default-scheduler                    Successfully assigned default/api-7b89bd4755-4lc6k to srvweb05.beirario.intranet
  Warning  BackOff    3m2s (x28 over 8m8s)   kubelet, srvweb05.beirario.intranet  Back-off restarting failed container
-- Felipe Flores
docker
kubectl
kubernetes
node.js

1 Answer

3/8/2019

All I can say here - you are providing a task that finish with command: ["/bin/sh","-c", "node", "servidor.js"]. Instead of this you should provide command in that way so it never completes.

Describe your pods shows that container in the pod has been completed successfully with exit code 0

Containers:
  ex-node:
    Container ID:  docker://836ffd771b3514fd13ae3e6b8818a7f35807db55cf8f756e962131823a476675
    Image:         node:8-alpine
    Image ID:      docker-pullable://node@sha256:8e9987a6d91d783c56980f1bd4b23b4c05f9f6076d513d6350fef8fe09ed01fd
    Port:          3000/TCP
    Host Port:     0/TCP
    Command:
      /bin/sh
      -c
      node
      servidor.js
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 08 Mar 2019 14:29:54 +0000
      Finished:     Fri, 08 Mar 2019 14:29:54 +0000
-- VKR
Source: StackOverflow