0

I am trying to build a docker image for python script and created CronJob and deployed it to Kubernetes, but i am not able to see any logs . if i deploy it to a pod i am able to see logs. Kindly let me know if i need to make any changes to Cronjob code. Below are the Docker file and Cronjob code

DockerFile:

from python:3.9-slim-buster

RUN apt-get update && apt-get install build-essential -y
RUN apt install libpq-dev python3-dev -y
RUN pip install --upgrade pip
COPY . /
RUN ls
RUN pip3 install -r ./requirements.txt
RUN mkdir /app/health
RUN chmod +x /app/scripts/main.py
WORKDIR /app
RUN ls
WORKDIR /app/scripts

RUN ls

ENTRYPOINT ["python", "/app/scripts/main.py"]

Deployment[CronJob]

apiVersion: batch/v1
kind: CronJob
metadata: 
  name: <cronjob name>
  namespace: <namespace>
spec:  
  jobTemplate: 
    spec:     
      template:        
        spec:          
          containers: 
            - name: <containername>
              image: <imagename>
              imagePullPolicy: Always
              command: ["/bin/sh"]
              args: [python, main.py]                      
          restartPolicy: OnFailure          
  schedule: "59 6 * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 0 
sumesh
  • 55
  • 7
  • can you please share kubectl commands you used for deployment as a pod and as a cron job as well as for viewing logs? – rok Dec 22 '22 at 10:25
  • Check this [SO](https://stackoverflow.com/questions/56457601/kubernetes-cronjob-to-run-python-script) link.Let me know if this is helpful. – Fariya Rahmat Dec 22 '22 at 11:08
  • What happens when you actually run it? Looking at the YAML file, the `command:` and `args:` you have are incorrect but also unnecessary; does just deleting those two lines help? – David Maze Dec 22 '22 at 12:14
  • @DavidMaze I changed the command to ```["python"]``` and ```args:``` is same but cronjobs is getting started but no logs. Python file has print statement which gets printed when deployed using pods but only in cronjobs i am not getting any logs – sumesh Jan 09 '23 at 04:36

0 Answers0