<p>I'm having an issue whereby cronjob in kubernetes doesnt seem to work.
Below is the test Dockerfile used</p>

<pre><code>FROM debian:jessie

RUN apt-get update
RUN apt-get -y install --no-install-recommends cron

RUN echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' | crontab

RUN echo '0-59/2 * * * 0-4 export ENV=dev RECIPIENT=email@example.com; echo "$(date) ${ENV} ${RECIPIENT}" &gt;&gt; /var/log/cron.log' | crontab

CMD ["cron", "-f", "-L", "15"]
</code></pre>

<p>Using native docker to run the above dockerfile, I could see the output in the logfile but not in kubernetes. Checked the events but didn't notice anything unusual.</p>

<p>Below is the replicationcontroller yaml file used</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    name: cron-test
  name: cron-test
spec:
  replicas: 1
  selector:
    name: cron-test
  template:
    metadata:
      labels:
        name: cron-test
    spec:
      containers:
        - name: cron-test
          image: example/cron-test:latest
          resources:
            limits:
              cpu: 100m
              memory: 512Mi
          imagePullPolicy: Always
</code></pre>

<p>Thanks</p>

<p>Somehow I got it working by switching the Dockerfile around</p>

<p>Dockerfile</p>

<pre><code>FROM debian:jessie

RUN apt-get update
RUN apt-get -y install --no-install-recommends cron

COPY . /src
WORKDIR /src

RUN cp run.sh /run.sh \
    &amp;&amp; chmod a+x /run.sh \
    &amp;&amp; touch /var/log/cron.log

CMD ["/run.sh"]
</code></pre>

<p>run.sh</p>

<pre><code>#!/bin/sh

cat &lt;&lt; EOF &gt; /tmp/setup-env.sh
export ENV=dev
export RECIPIENT=email@example.com
EOF

crontab /src/crons.conf
exec cron -f -L 15
</code></pre>

<p>crons.conf</p>

<pre><code>PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
0-59/2 * * * 0-4 . /tmp/setup-env.sh ; echo "$(date) ${ENV} ${RECIPIENT}" &gt;&gt; /var/log/cron.log 2&gt;&amp;1
</code></pre>

<p>My guess is that because <code>crontab /src/crons.conf</code> was running at build time and build file-system is different from running file-system i.e building with native docker (rootfs) and running it on kubernetes (overlayfs).</p>
