We are following a microservice based architecture, where I 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?
If yes, on what base image should I build my node application?
And what are the steps I should include to my docker file, to also verify my cron executed logs, run both node application and cron jobs?
You can define a health check in the dockerfile. This is also possible in docker-compose and running docker container via cli.
I always recommend disable possible previous healthcheck if you inherit your dockerfile from another non-basic image, adding HEALTHCHECK NONE
after FROM
clause.
Once it's done, define your own health check adding to your dockerfile:
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.
For further information about options you can see Docker documentation healthcheck
I understand that you are looking for a job scheduler, by my experience putting more than 1 process per container is not the best idea, 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.