2

当我使用 docker run 运行它时,我有一个运行良好的 docker 容器。我正在尝试将该容器放入 pod 中,但我遇到了问题。pod 的第一次运行显示状态为“已完成”。然后 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 获取 pod

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

我假设我们需要一个循环来保持容器在这种情况下运行。但我不明白为什么它在使用 docker 运行时有效,而在 pod 内时无效。它不应该表现相同吗?

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

4

2 回答 2

2

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

  command: ["sh"]
  stdin: true

替换为图像可能具有的任何其他外壳shbash

然后您可以使用以下命令放入容器中exec

 kubectl exec -it <pod-name> sh

-c <container-name>如果 pod 有多个容器,则添加参数。

于 2018-08-05T21:27:48.413 回答
0

你确定你运行你的软件docker run ... -d ... <command>并且它一直在运行并且你在你的 pod 中使用相同的命令吗?在某些情况下,如果您将在 docker 上运行的东西与否进行比较,-it-d可能会发现自己处于紧要关头,因为他们希望终端与用户通信并在 tty 不可用时退出(提示:可以运行 pod/container tty: true

您不太可能拥有在分离的 docker 中运行而不在 kube 中运行的软件。

于 2018-08-03T16:59:43.187 回答