<p>I have to create a readyness and liveness probe for a node.js container (docker) in kubernetes. My problem is that the container is NOT a server, so I cannot use an http request to see if it is live. </p>

<p>My container runs a <a href="https://www.npmjs.com/package/cron" rel="nofollow noreferrer">node-cron</a> process that download some csv file every 12 h, parse them and insert the result in elasticsearch. </p>

<p>I know I could add express.js but I woud rather not do that just for a probe.</p>

<p>My question is:</p>

<ol>
<li>Is there a way to use some kind of <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command" rel="nofollow noreferrer">liveness command probe</a>? If it is possible, what command can I use?</li>
<li>Inside the container, I have <a href="https://www.npmjs.com/package/pm2" rel="nofollow noreferrer">pm2</a> running the process. Can I use it in any way for my probe and, if so, how?</li>
</ol>

<p><strong>Liveness command</strong></p>

<p>You <em>can</em> use a <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command" rel="nofollow noreferrer">Liveness command</a> as you describe. However, I would recommend to design your job/task for Kubernetes.</p>

<p><strong>Design for Kubernetes</strong></p>

<blockquote>
  <p>My container runs a node-cron process that download some csv file <strong>every 12 h</strong>, parse them and insert the result in elasticsearch.</p>
</blockquote>

<p>Your job is not executing so often, if you deploy it as a service, it will <strong>take up resources all the time</strong>. And when you write that you want to use <a href="https://www.npmjs.com/package/pm2" rel="nofollow noreferrer">pm2</a> for your process, I would recommend another design. As what I understand, PM2 is a process manager, but Kubernetes is also a process manager <em>in a way</em>.</p>

<p><strong>Kubernetes native CronJob</strong></p>

<p>Instead of handling a <em>process</em> with pm2, implement your <strong>process</strong> as a <strong>container image</strong> and schedule your job/task with <a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/" rel="nofollow noreferrer">Kubernetes CronJob</a> where you specify your <strong>image</strong> in the <code>jobTemplate</code>. With this design, you don't have any <em>livenessProbe</em> but your task will be restarted if it fails, e.g. fail to insert the result to elasticSearch due to a network problem.</p>
