0

Would anyone be so kind as to point me to the piece of documentation which explains the following phenomenon?

When we run kubectl run --rm --stdin --tty --image hello-world hello-pod , it's being restarted by Kubernetes automatically. Why does Kubernetes forget to delete it?

At the same time, if we run kubectl run --rm --stdin --tty --image busybox busy-pod, it's being automatically deleted (which seems to be quite legit).

Any suggestion is appreciated. Thank you.

1 Answer 1

2

The reason why the first pod is being restarted is that there's probably an error there and kubernetes keeps restarting it "in the hope" that it will solve the issue eventually. When you run that, you get a 'CrashLoopBack', but then Kubernetes does delete it eventually, but only after a while:

kubectl run --rm --stdin --tty --image hello-world hello-pod
pod "hello-pod" deleted
error: timed out waiting for the condition

Kubernetes deletes the second pod also the moment you exit the tty (ctrl + D). And the reason for that is that the process ends and you've added the '--rm' option which does exactly that - it automatically deletes pods when the process terminates, which in this case means just exiting the terminal/bash/shell etc.

3
  • Thank you. Of course, I suggested that the application in the container returns an error code, but it doesn't: docker run hello-world >/dev/null; echo "${?}" returns 0. :-( Dec 23, 2022 at 16:52
  • My answer is partially wrong though, I realise now. The second time I've created the pod, kubernetes keeps restarting it. But the reason for that is, indeed, an error (that's why you can see CrashLoopBackOff when you list the pods). The description is not necessarily more useful: "Back-off restarting failed container". But something does return a non-zero code, but I admit I'm not sure what. That's the reason though why kubernetes keeps restarting it instead of deleting it. But that's not consistent, sometimes it does delete it at some point, because the process exits with 0. Interesting :)
    – Lethargos
    Dec 23, 2022 at 17:49
  • Yes, that's exactly what I can't get. Why Kubernetes considers it as failed? Dec 23, 2022 at 18:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .