I have an API as a Kubernetes service, and I need to run an endpoint in the API every hour. (heavy statistic calculation, takes around 3-5 minutes)
Currently I am using curl to call the end point directly:
containers:
- name: callout
image: 'buildpack-deps:curl'
args:
- /bin/sh
- '-ec'
- 'curl http://api-service/v1/Stats/CalculateStats'
The problem is the task is sent to service, and it ends up on one of the pods. Running the calculation keeps the pod busy, and the other requests coming from regular users via front-end slow down.
How can I create a dedicated pod from the same API image with a higher CPU request (so it can run faster) and run the calculation on it, then remove the pod and repeat the process on the next schedule?
Thanks
This is what came to my mind:
0
by default. This deployment can be updated whenever the production deployment is updated, so both deployments run the same version of the appplication.In the cronjob:
1
curl
-command0
This will ensure that the additional resources are only consumed when the expensive request is executed. A downside of this approach is that the deployment of the pod may fail if no sufficient resources are available, so we should monitor the cluster and keep some resource "ready" for when the deployment is scaled up. This can be done, e.g., through a cluster autoscaler on AWS. The scaling may take some time, so the cronjob should be able to handle this kind of delay.
By the by: I would also suggest to secure/hide the endpoint with the "expensive operation" from public, such that no user is able to tear down the production deployment, either "by accident" or out of malicious intentions.