How to perform autorestart of Pods at scheduled time in openshift

439 Views Asked by At

I am having a list of pods running java applications,want to have a schedule restart of pods automatically.How it can be performed.I have tried with having a cron job inside an ocp file but it didn't work.

Help me with some suggestions

1

There are 1 best solutions below

0
On

If the CronJob didn't work, you likely need to authorize the ServiceAccount running the CronJob Pod to be able to list & delete the Java Pods. Otherwise it will lack the permissions to do so.

There are a long list of alternatives, but the constraints of your environment and the motivation to restart the applications would be important to understand to determine a good approach. Examples:

  • Add a Rest API to the Java application which can trigger graceful shutdown and trigger it from the CronJob.
  • If you don't really need this to be scheduled and it will suffice to be periodic restart, consider setting pod.spec.activeDeadlineSeconds . This will ensure the Pod terminates after running for the specified duration.
  • Share the process namespace between containers in the Java Pod and add a container that kills Java process at the scheduled time.