Pod进入CrashLoopBackOff的状态并反复重启-退出代码为0

时间:2018-08-03 14:02:30

标签: docker kubernetes kubernetes-pod

我有一个docker容器,当我使用docker run运行它时,它运行良好。我正在尝试将该容器放入豆荚中,但遇到了问题。窗格的第一次运行将状态显示为“已完成”。然后,pod继续以CrashLoopBackoff状态重启。但是,退出代码为0。

这是kubectl describe pod的结果:

Name:           messagingclientuiui-6bf95598db-5znfh
Namespace:      mgmt
Node:           db1mgr0deploy01/172.16.32.68
Start Time:     Fri, 03 Aug 2018 09:46:20 -0400
Labels:         app=messagingclientuiui
            pod-template-hash=2695115486
Annotations:    <none>
Status:         Running
IP:             10.244.0.7
Controlled By:  ReplicaSet/messagingclientuiui-6bf95598db
Containers:
  messagingclientuiui:
    Container ID:   docker://a41db3bcb584582e9eacf26b02c7ef26f57c2d43b813f44e4fd1ba63347d3fc3
Image:          172.32.1.4/messagingclientuiui:667-I20180802-0202
Image ID:       docker-pullable://172.32.1.4/messagingclientuiui@sha256:89a002448660e25492bed1956cfb8fff447569e80ac8b7f7e0fa4d44e8abee82
Port:           9087/TCP
Host Port:      0/TCP
State:          Waiting
  Reason:       CrashLoopBackOff
Last State:     Terminated
  Reason:       Completed
  Exit Code:    0
  Started:      Fri, 03 Aug 2018 09:50:06 -0400
  Finished:     Fri, 03 Aug 2018 09:50:16 -0400
Ready:          False
Restart Count:  5
Environment Variables from:
  mesg-config  ConfigMap  Optional: false
Environment:     <none>
Mounts:
  /docker-mount from messuimount (rw)
  /var/run/secrets/kubernetes.io/serviceaccount from default-token-2pthw (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          False
  PodScheduled   True
Volumes:
  messuimount:
    Type:          HostPath (bare host directory volume)
    Path:          /mon/monitoring-messui/docker-mount
    HostPathType:
  default-token-2pthw:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-2pthw
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason                 Age              From                            Message
  ----     ------                 ----             ----                      -------
  Normal   Scheduled              4m               default-scheduler         Successfully assigned messagingclientuiui-6bf95598db-5znfh to db1mgr0deploy01
  Normal   SuccessfulMountVolume  4m               kubelet, db1mgr0deploy01  MountVolume.SetUp succeeded for volume "messuimount"
  Normal   SuccessfulMountVolume  4m               kubelet, db1mgr0deploy01  MountVolume.SetUp succeeded for volume "default-token-2pthw"
  Normal   Pulled                 2m (x5 over 4m)  kubelet, db1mgr0deploy01  Container image "172.32.1.4/messagingclientuiui:667-I20180802-0202" already present on machine
  Normal   Created                2m (x5 over 4m)  kubelet, db1mgr0deploy01  Created container
  Normal   Started                2m (x5 over 4m)  kubelet, db1mgr0deploy01  Started container
  Warning  BackOff                1m (x8 over 4m)  kubelet, db1mgr0deploy01  Back-off restarting failed container

kubectl获得豆荚

      NAME                              READY     STATUS             RESTARTS   AGE
messagingclientuiui-6bf95598db-5znfh   0/1       CrashLoopBackOff   9          23m

在这种情况下,我假设我们需要一个循环来保持容器运行。但是我不明白为什么它在使用docker运行时会起作用,而在Pod内时却不起作用。它的行为不应该一样吗?

除了运行kubectl描述pod和kubectl日志外,我们如何调试CrashLoopBackOff状态

2 个答案:

答案 0 :(得分:0)

确定要以docker run ... -d ... <command>的身份运行软件,并且该软件保持运行状态,并且在pod中使用相同的确切命令?在某些情况下,如果将在docker上运行的事物与-it而不是-d进行比较,您可能会发现自己处于紧要关头,因为他们希望终端与用户通信并在tty不可用时退出。 :容器/容器可以与tty: true一起运行)

您不太可能拥有在独立的docker中运行且不在kube中运行的软件。

答案 1 :(得分:0)

如果在后台运行至少一个进程,则该容器将以退出代码0终止。要保持容器运行,请将它们添加到部署配置中:

  command: ["sh"]
  stdin: true

在图像可能具有的任何其他外壳上将sh替换为bash

然后您可以使用exec放到容器内:

 kubectl exec -it <pod-name> sh

如果广告连播具有多个容器,请添加-c <container-name>参数。