Why is a kubernetes pod with a simple hello-world image getting a CrashLoopBackOff message

10/19/2018

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

Why CrashLoopBackOff?

-- Snowcrash
kubernetes
pod

2 Answers

10/19/2018

The hello-world is actually exiting meaning Kubernetes thinks its crashing, and keeps restarting and exiting and going in CrashLoppBackOff. When you docker run your hello-world container you get this:

$ 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/
$ 

So, it's a one-time thing and not a service. Kubernetes has Jobs or CronJobs for these types of workloads.

-- Rico
Source: StackOverflow

10/19/2018

In this case the expected behavior is correct. The hello-world container is meant to print some messages and then exit after completion. So this is why you are getting CrashLoopBackOff -

Kubernetes runs a pod - the container inside runs the expected commands and then exits.

Suddenly there is nothing running underneath - so the pod is ran again -> same thing happens and the number of restarts grows.

You can see that inkubectl describe pod where Terminated state is visible and the Reason for it is status Completed. If you would choose a container image which does not exit after completion the pod would be in running state.

-- aurelius
Source: StackOverflow