Pod进入CrashLoopBackOff的状态,并反复重新启动-退出代码为0 [英] Pod gets into status of CrashLoopBackOff and gets restarted repeatedly - Exit code is 0

查看:71
本文介绍了Pod进入CrashLoopBackOff的状态,并反复重新启动-退出代码为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a docker container that is running fine when I run it using docker run. I am trying to put that container inside a pod but I am facing issues. The first run of the pod shows status as "Completed". And then the pod keeps restarting with CrashLoopBackoff status. The exit code however is 0.

这是kubectl describe pod的结果:

Here is the result of 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获得豆荚

kubectl get pods

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

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

I am assuming we need a loop to keep the container running in this case. But I dont understand why it worked when it ran using docker and not working when it is inside a pod. Shouldnt it behave the same ?

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

How do we henerally debug CrashLoopBackOff status apart from running kubectl describe pod and kubectl logs

推荐答案

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

The container would terminate with exit code 0 if there isn't at least one process running in the background. To keep the container running, add these to the deployment configuration:

  command: ["sh"]
  stdin: true

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

Replace sh with bash on any other shell that the image may have.

然后您可以使用 exec 放入容器中:

Then you can drop inside the container with exec:

 kubectl exec -it <pod-name> sh

如果pod具有多个容器,请添加 -c< container-name> 参数.

Add -c <container-name> argument if the pod has more than one container.

这篇关于Pod进入CrashLoopBackOff的状态,并反复重新启动-退出代码为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆