kubernetes集群中的应用程序nodejs不会保持运行-CrashLoopBackOff

时间:2019-03-08 13:23:11

标签: node.js docker kubernetes kubectl

我在nodejs中有一个小应用程序,可以使用kubernetes进行测试,但是似乎该应用程序无法保持运行状态

我将开发测试的所有代码都放在了GitHub

我正在运行kubectl create -f deploy.yaml 有效,但是..

[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:
  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

3 个答案:

答案 0 :(得分:0)

我在这里只能说-您提供的任务以command: ["/bin/sh","-c", "node", "servidor.js"]结尾。 相反,您应该以这种方式提供命令,以使它永远不会完成。

描述您的豆荚显示豆荚中的容器已成功完成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

答案 1 :(得分:0)

你可以在你的代码中使用“process.stdout.write”方法,这会导致k8s会话丢失。不要在标准输出中打印任何内容!

答案 2 :(得分:0)

尝试使用 pm2 Get-ADGroupMember。它将您的 nodejs 应用程序作为后台进程启动。