Alok Kumar Singh
Alok Kumar Singh

Reputation: 2549

Disable Crashloop feature in Kubernetes for a single Deployment - use case: reload

I reload my process running as a Kubernetes Deployment by exiting 0. Sometimes the restarts may be frequent depending on external factors. It does not affect my application as the restarts are intentional and graceful shutdown happens.

Problem is Kubernetes sees this as a problem and puts my pod into Crashloop. Please suggest how to disable Crashloop in pods.

I am using restart and Kubernetes Deployment as a feature.

Upvotes: 1

Views: 1692

Answers (2)

PjoterS
PjoterS

Reputation: 14092

Posting this as Community Wiki as good point was mention in comment section by @Matt.

Unfortunately, at this moment changing CrashLoopBackOff as this is Work as Intended behavior. As pointed in Sysdig documentation about CrashLoopBackOff

A CrashloopBackOff means that you have a pod starting, crashing, starting again, and then crashing again.

There is an open thread on Github for some CrashLoopBackoff changes, which might be useful in the future with scenarios like this, however it's open since Dec 2017.

Restart Policy as default is set to Always, so chaning it won't help.

The default value is Always and the restartPolicy only refers to restarts of the containers by the kubelet on the same node (so the restart count will reset if the pod is rescheduled in a different node). Failed containers that are restarted by the kubelet are restarted with an exponential back-off delay (10s, 20s, 40s …) capped at five minutes, and is reset after ten minutes of successful execution.

Good explanation about Network Policy differences can be found in this Stackoverflow thread.

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.

Failure 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.

As workaround

You can think about using Kubernetes jobs, as per @Pythonista answer and depends on your needs you can also use Kubernetes CronJobs.

Upvotes: 1

Pythonista
Pythonista

Reputation: 117

If you are not managing a long-running process you might want to look at using a Kubernetes job instead of deployment.

Upvotes: 1

Related Questions