run cron jobs inside container in background, when i am having a nodejs application as endpoint in foreground?

0 votes
I am trying to deploy my application inside a kubernetes cluster by helm package. I have a nodejs application which queries cron jobs from database and should add these jobs to crontab file inside the same container.

So when I expose my container as a nodejs app in a port, I will make a add job request and these jobs are formatted to cron job type, and these entries needed to be added to crontab and execute these jobs in background.

Can this be achieved?
Sep 17, 2018 in Kubernetes by lina
• 8,110 points
100 views

2 answers to this question.

0 votes

I think that you are looking for a job scheduler, you should try putting more than 1 process per container, maybe you can use another approach using an extra microservice that runs that jobs.

I recommend using Agenda

https://github.com/agenda/agenda

You can create an Agenda worker that has the code for the different jobs and the only thing that you need is to send a scheduled job or now execution, by this architecture you can have multiple agendas also as a sidecar container inside the same pod of your node application.

answered Sep 17, 2018 by Kalgi
• 42,540 points
0 votes

You can define a health check in the dockerfile. This is also possible in docker-compose and running docker container via cli.

HEALTHCHECK <options> CMD <your command with args> || exit 1

That will provoke that when you do docker ps you'll see if a container is running or stopped, and in case it's running, if it's healthy or not, i.e, if your command is being executed / has been executed properly.

answered Sep 17, 2018 by lina
• 8,110 points

Related Questions In Kubernetes

0 votes
1 answer
0 votes
1 answer

Run a cron job once in N hours

If you want your cron job to ...READ MORE

answered Sep 18, 2018 in Kubernetes by Kalgi
• 42,540 points
42 views
0 votes
1 answer
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
3,117 views
+3 votes
1 answer
0 votes
1 answer

Pods IP address from inside a container in the pod

Make sure that your pod yaml file ...READ MORE

answered Aug 29, 2018 in Kubernetes by Kalgi
• 42,540 points
173 views