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 
4
  • can you please share kubectl commands you used for deployment as a pod and as a cron job as well as for viewing logs? Commented Dec 22, 2022 at 10:25
  • Check this SO link.Let me know if this is helpful. Commented Dec 22, 2022 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? Commented Dec 22, 2022 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 Commented Jan 9, 2023 at 4:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.