the docker official image hello-world keep reporting 'Back-off restarting failed container' with kubectl command

3/5/2021

I keep seeing Back-off restarting failed container when try to use docker official image https://hub.docker.com/_/hello-world to create any pod\deployment. When I switch to other images like nginx everything works well.

How can I debug and fix this issue?

Below are the event logs after creating the pod with kubectl.

root@ip-10-229-68-221:~# kubectl get event --watch
LAST SEEN   TYPE      REASON              OBJECT                             MESSAGE
24s         Normal    Scheduled           pod/helloworld-656898b9bb-98vrv    Successfully assigned default/helloworld-656898b9bb-98vrv to kind-lab-worker
23s         Normal    Pulling             pod/helloworld-656898b9bb-98vrv    Pulling image "hello-world:linux"
16s         Normal    Pulled              pod/helloworld-656898b9bb-98vrv    Successfully pulled image "hello-world:linux" in 7.371731633s
1s          Normal    Created             pod/helloworld-656898b9bb-98vrv    Created container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-98vrv    Started container hello-world
1s          Normal    Pulled              pod/helloworld-656898b9bb-98vrv    Container image "hello-world:linux" already present on machine
13s         Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
24s         Normal    Scheduled           pod/helloworld-656898b9bb-sg6fs    Successfully assigned default/helloworld-656898b9bb-sg6fs to kind-lab-worker
23s         Normal    Pulling             pod/helloworld-656898b9bb-sg6fs    Pulling image "hello-world:linux"
13s         Normal    Pulled              pod/helloworld-656898b9bb-sg6fs    Successfully pulled image "hello-world:linux" in 9.661065021s
13s         Normal    Created             pod/helloworld-656898b9bb-sg6fs    Created container hello-world
13s         Normal    Started             pod/helloworld-656898b9bb-sg6fs    Started container hello-world
13s         Normal    Pulled              pod/helloworld-656898b9bb-sg6fs    Container image "hello-world:linux" already present on machine
11s         Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
24s         Normal    Scheduled           pod/helloworld-656898b9bb-vhhfm    Successfully assigned default/helloworld-656898b9bb-vhhfm to kind-lab-worker
23s         Normal    Pulling             pod/helloworld-656898b9bb-vhhfm    Pulling image "hello-world:linux"
18s         Normal    Pulled              pod/helloworld-656898b9bb-vhhfm    Successfully pulled image "hello-world:linux" in 5.17232683s
3s          Normal    Created             pod/helloworld-656898b9bb-vhhfm    Created container hello-world
2s          Normal    Started             pod/helloworld-656898b9bb-vhhfm    Started container hello-world
3s          Normal    Pulled              pod/helloworld-656898b9bb-vhhfm    Container image "hello-world:linux" already present on machine
2s          Warning   BackOff             pod/helloworld-656898b9bb-vhhfm    Back-off restarting failed container
24s         Normal    SuccessfulCreate    replicaset/helloworld-656898b9bb   Created pod: helloworld-656898b9bb-vhhfm
24s         Normal    SuccessfulCreate    replicaset/helloworld-656898b9bb   Created pod: helloworld-656898b9bb-sg6fs
24s         Normal    SuccessfulCreate    replicaset/helloworld-656898b9bb   Created pod: helloworld-656898b9bb-98vrv
24s         Normal    ScalingReplicaSet   deployment/helloworld              Scaled up replica set helloworld-656898b9bb to 3
79s         Normal    Killing             pod/nginx                          Stopping container nginx
0s          Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
0s          Normal    Pulled              pod/helloworld-656898b9bb-sg6fs    Container image "hello-world:linux" already present on machine
0s          Normal    Created             pod/helloworld-656898b9bb-sg6fs    Created container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-sg6fs    Started container hello-world
0s          Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-vhhfm    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
0s          Normal    Pulled              pod/helloworld-656898b9bb-vhhfm    Container image "hello-world:linux" already present on machine
0s          Normal    Pulled              pod/helloworld-656898b9bb-98vrv    Container image "hello-world:linux" already present on machine
0s          Normal    Created             pod/helloworld-656898b9bb-vhhfm    Created container hello-world
1s          Normal    Created             pod/helloworld-656898b9bb-98vrv    Created container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-vhhfm    Started container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-98vrv    Started container hello-world
0s          Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-vhhfm    Back-off restarting failed container
0s          Normal    Pulled              pod/helloworld-656898b9bb-sg6fs    Container image "hello-world:linux" already present on machine
0s          Normal    Created             pod/helloworld-656898b9bb-sg6fs    Created container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-sg6fs    Started container hello-world
0s          Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-vhhfm    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-vhhfm    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
0s          Normal    Pulled              pod/helloworld-656898b9bb-vhhfm    Container image "hello-world:linux" already present on machine
0s          Normal    Created             pod/helloworld-656898b9bb-vhhfm    Created container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-vhhfm    Started container hello-world
0s          Warning   BackOff             pod/helloworld-656898b9bb-vhhfm    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
0s          Normal    Pulled              pod/helloworld-656898b9bb-98vrv    Container image "hello-world:linux" already present on machine
0s          Normal    Created             pod/helloworld-656898b9bb-98vrv    Created container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-98vrv    Started container hello-world
0s          Warning   BackOff             pod/helloworld-656898b9bb-98vrv    Back-off restarting failed container
0s          Warning   BackOff             pod/helloworld-656898b9bb-vhhfm    Back-off restarting failed container
0s          Normal    Pulled              pod/helloworld-656898b9bb-sg6fs    Container image "hello-world:linux" already present on machine
0s          Normal    Created             pod/helloworld-656898b9bb-sg6fs    Created container hello-world
0s          Normal    Started             pod/helloworld-656898b9bb-sg6fs    Started container hello-world
0s          Warning   BackOff             pod/helloworld-656898b9bb-sg6fs    Back-off restarting failed container
-- Chen Zhao
kubernetes

1 Answer

3/5/2021

hello-world image is not a long-running process: it just outputs text and stops.

Kubernetes Pod is by default expecting long-running processes, and if it stops it automatically restart the container.

This behavior is defined by the restartPolicy parameter of a pod and can have different values:

  • Always: always restart stopped container (the default)
  • OnFailure: restart containers that exited with !=0
  • Never: don't restart containers

So in your case you should use one of the 2 last as the container is expected to stop normally.

-- zigarn
Source: StackOverflow