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,
- download the new files on daily 10 AM
- 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.
CodePudding user response:
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.