为什么 Kubernetes 重新启动一些 pod 而不重新启动另一个?

为什么 Kubernetes 重新启动一些 pod 而不重新启动另一个?

有人能告诉我一份能解释以下现象的文献吗?

当我们运行 时kubectl run --rm --stdin --tty --image hello-world hello-pod,它会被 Kubernetes 自动重启。为什么 Kubernetes 会忘记删除它?

同时,如果我们运行kubectl run --rm --stdin --tty --image busybox busy-pod,它会被自动删除(这似乎是合法的)。

任何建议都值得赞赏。谢谢。

答案1

第一个 pod 被重启的原因是那里可能存在错误,而 kubernetes 不断重启它“希望”它最终能解决这个问题。当你运行它时,你会得到一个“CrashLoopBack”,但 Kubernetes 最终会删除它,但只是在一段时间之后:

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

当您退出 tty(ctrl + D)时,Kubernetes 也会删除第二个 pod。原因是进程结束,并且您添加了“--rm”选项,该选项的作用正是如此 - 它会在进程终止时自动删除 pod,在这种情况下,这意味着只需退出终端/bash/shell 等。

相关内容