Kubernetes: how to restart pods on memory or/and time limits?

10/30/2019

Is there a way to restart pods automatically after some time or when they reach some memory limit?

I want achieve the same behavior as gunicorn(or any mainstream process manager does)

-- kharandziuk
kubernetes

1 Answer

10/30/2019

Memory limit

If you set a limit for the memory on a container in the podTemplate, this pod will be restarted if it uses more than specified memory.

resources:
  limits:
    memory: 128Mi

See Managing Compute Resources for Containers for documentation

Time limit

This can be done in many different ways, internally by calling exit(1) or stop responding on a configured livenessProbe. Or externally, e.g. by configuring a CronJob.

-- Jonas
Source: StackOverflow