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,220 points
2,260 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
• 52,360 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,220 points

Related Questions In Kubernetes

+1 vote
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
• 52,360 points
777 views
0 votes
1 answer
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

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

answered Jan 17, 2019 in Others by anonymous
15,303 views
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,360 points

reshown Apr 12, 2019 by Kalgi 6,926 views
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
• 52,360 points
2,361 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP