0

I am using Django Cron package in a docker container where I specify my cron functions like this:

class CreateSnapshots(CronJobBase):
    RUN_EVERY_MINS = 15  # every 15 mins

    schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
    code = 'crontab.cronjobs.CreateSnapshots' 

    def do(self):
        print("Running CreateSnapshots now..")

In my docker-entrypoint.sh for Kubernetes, I specify this:

python manage.py runcrons

The cronjob doesn't run every 15 minutes as instructed but when I do python manage.py runcrons in the bash of container, the cronjob runs immediately. Any idea why is it not running every 15 minutes as specified? or a piece of configuration I am missing?

I have specified this in my settings.py:

CRON_CLASSES = [
    "crontab.cronjobs.CreateSnapshots",
]

My Kubernetes Deployment Spec:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert -f docker-compose.yml
    kompose.version: 1.14.0 (fa706f2)
  creationTimestamp: null
  labels:
    io.kompose.service: cronjobs
  name: cronjobs
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: cronjobs
    spec:
      imagePullSecrets:
      - name: mycompregcred
      containers:
      - args:
        - python
        - manage.py
        - runserver
        - 0.0.0.0:8003
        image: eu.gcr.io/my-project-123/cronjobs
        name: cronjobs
        ports:
        - containerPort: 8003
        resources: {}
        volumeMounts:
        - mountPath: /cronjobs
          name: cronjobs-claim0
        - mountPath: /cronjobs/common
          name: cronjobs-claim1
      restartPolicy: Always
      volumes:
      - name: cronjobs-claim0
        persistentVolumeClaim:
          claimName: cronjobs-claim0
      - name: cronjobs-claim1
        persistentVolumeClaim:
          claimName: cronjobs-claim1
status: {}

And my docker-compose.yaml's cronjob app part:

  cronjobs:
    image: cronjobs
    build: ./cronjobs
    depends_on:
      - db

My full docker-entrypoint.sh looks like this:

#!/bin/sh

wait-for-it db:5432
python manage.py collectstatic --no-input
python manage.py migrate django_cron
python manage.py runcrons

gunicorn cronjobs.wsgi -b 0.0.0.0:8000
sshussain270
  • 1,785
  • 4
  • 25
  • 49
  • That sounds like something has gone awry in between the image's `ENTRYPOINT`/`CMD` and the pod's `command:`/`args:`. Can you edit the question to include relevant fragments of your image's Dockerfile and of your Kubernetes deployment spec? – David Maze Sep 21 '20 at 00:43
  • @DavidMaze Please see the question again, I added. – sshussain270 Sep 21 '20 at 01:19
  • The `args:` in the deployment spec overrides the `CMD` in the Dockerfile, so (probably) your pods aren't running the script you show, they're running an HTTP server instead. – David Maze Sep 21 '20 at 11:36

0 Answers0