Can someone shed light on --restart=never option? In what cases would you use it . . .

SMB:
Can someone shed light on --restart=never option? In what cases would you use it? I have seen people using it across, in some cases for temporary busybox pods.

Kalyan Kumar Mudi:
Two aspects that I know of -

  1. Pre 1.18, when “kubectl run” was used widely to create pod, deployment, job etc, “–restart” option played a crucial role. It used to have different values “Never”, “Always”, “OnFailure” based on what object is being created. In 1.18, I don’t think its used as such.
  2. For a temporary busybox pod, which is very useful to - 1) test connectivity to another pod/service, 2) do a nslookup, 3) get ad-hoc container output (env, cat log, whoami, hostname) - the job of the temp pod is used to output the requested information and go die (and preferably be removed as well). In this case, if you don’t use “restart=Never”, the pod will continuously try to restart and will go on a crash loop - potentially hanging and probably preventing the desired output.

Mohamed Ayman:
Always means that the container will be restarted even if it exited with a zero exit code (i.e. successfully). This is useful when you don’t care why the container exited, you just want to make sure that it is always running (e.g. a web server). This is the default.
OnFailure means that the container will only be restarted if it exited with a non-zero exit code (i.e. something went wrong). This is useful when you want accomplish a certain task with the pod, and ensure that it completes successfully - if it doesn’t it will be restarted until it does.
Never means that the container will not be restarted regardless of why it exited.

SMB:
Great. Thank you guys!! Definitely helps.