为什么带有简单hello-world图像的kubernetes pod会收到CrashLoopBackOff消息

时间:2018-10-19 11:00:12

标签: kubernetes pod

pod.yml

apiVersion: v1
kind: Pod
metadata:
    name: hello-pod
    labels:
        zone: prod
        version: v1
spec:
    containers:
    - name: hello-ctr
      image: hello-world:latest
      ports:
      - containerPort: 8080

kubectl create -f pod.yml

kubectl get pods
NAME        READY     STATUS             RESTARTS   AGE
hello-pod   0/1       CrashLoopBackOff   5          5m

为什么要CrashLoopBackOff

2 个答案:

答案 0 :(得分:2)

在这种情况下,预期的行为是正确的。 hello-world容器用于打印一些消息,然后在完成后退出。这就是为什么您得到CrashLoopBackOff-

Kubernetes运行一个pod-内部的容器运行预期的命令,然后退出。

突然下面没有任何东西在运行-因此吊舱再次运行->发生同样的事情,restarts的数量增加了。

您可以在kubectl describe pod状态为TerminatedReason为状态Completed的{​​{1}}中看到它。如果选择的容器映像在完成后不会退出,则容器将处于运行状态。

答案 1 :(得分:0)

hello-world实际上正在退出,这意味着Kubernetes认为它已崩溃,并继续在CrashLoppBackOff中重新启动,退出和继续。当您docker run hello-world容器时,将得到以下信息:

$ sudo docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
$ 

因此,这是一次性的事情,而不是一项服务。 Kubernetes具有JobsCronJobs这些类型的工作负载。