-1

I have a requirement to restart the Opensift container on everday 10 AM and execute a pre-script to perform file downloads.

Since my flask app is running on gunicorn 4 worker, i cannot place the file download logic on the flask application as it execute download logic on 4 times.

i.e. I have python flask app running in the Openshift which utilizes the 10 files (dynamic file with daily update). So case here is,

  1. download the new files on daily 10 AM
  2. Once new files are downloaded, restart the container. (restarted app will use the new files as it is arrived in the Persistent volume)

Please suggest how smart we can achieve it using liveness/readiness probe or any other way please suggest.

Prasanna C
  • 19
  • 6

1 Answers1

2

You can setup the NFS filesystem with ReadWriteMany access mode which will be shared across the 4 replicas of POD if you are running.

If you are running the 4 gunicorn workers inside the 1 POD backed by the single PVC. you can create an API or so to download a file, by invoking API you can simply update the downloaded file to the PVC file system.

To Restart the POD at 10 AM you can take the help of Kubernetes cronjobs, which will invoke your API endpoint to download files and the second cronjob at 10:15 AM, or after a few min of delay cronjob will restart the deployment.

Cronjobs : https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/

You can create the cronjob to run at 10 AM and restart the specific deployment or POD as per need.

Extra :

gunicorn is not required generally with K8s, you can multi-process, and scaling should be taken care by K8s itself HPA & VPA.

Python K8s client also available so using python also you can restart the deployment.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • thanks Harsh manvar this is a good reply with my exact flow -we been advised to do the above suggestion in liveness probe or in readiness probe - please suggest if it is good approach – Prasanna C Sep 07 '22 at 05:24
  • Hi Prasanna sorry not sure about your approach to liveness and readiness could you please share some more details? what's your plan – Harsh Manvar Sep 07 '22 at 05:41
  • As you said above to go with the cronjob in openshift, does the probe helps to restart the container and download the files. I.e. I can write a shell script which will check the below, 1. Check if the time is arrived 2. If yes, download the files using curl 3. Once download successful call exit 1 to Kil the container....... These steps are coded in a shell script and configured in livness probe. Please suggest which one better to go ahead whether cronjob or livenesse probe . – Prasanna C Sep 07 '22 at 17:39
  • liveness prove is mostly to check status of application, cronjob are mostly meant for similar requirement that you have. you can do it with liveness also but that would be extra processing each time to run and check however cronjob would be kind of optimal solution only get executed when time arrived instead checking on frequent interval. – Harsh Manvar Sep 08 '22 at 08:59
  • when we start the app using cron - Does it kill the previous instance or when should have the functionality (our code piece) to kill the previous day instance started by the same cron. – Prasanna C Oct 31 '22 at 12:09
  • @Haresh Manvar - Could you please answer the below question when we start the app using cron - Does it kill the previous instance or when should have the functionality (our code piece) to kill the previous day instance started by the same cron. – Prasanna C Oct 31 '22 at 12:12
  • cron will schedule the pod with different name each time so wont be able to run it again you can add functionality to auto kill or remove success or failed cron pods. feel free to add new question with more context as to get whole idea i might have to read through again. – Harsh Manvar Oct 31 '22 at 12:16