2

I am running a CronJob on Kubernetes (version 1.20). These are the relevant details:

concurrencyPolicy: Forbid
backoffLimit: 6

- command:
  - /bin/bash
  - -c
  - |
    exit 1;

restartPolicy: OnFailure

When I run the job, the pod that spins up restarts up to six times and then terminates. I describe the job, expecting to see that it failed, but instead I see this line:

Pods Statuses:  0 Running / 0 Succeeded / 0 Failed

I am really expecting to see this instead:

Pods Statuses:  0 Running / 0 Succeeded / 1 Failed

I have played around with the backoffLimit, but it was to no avail. The other settings need to be what they are at the moment.

  • Can you check the logs of the pod and make sure that the command is actually running? Also, this might be a dumb question but is the exit code of `/bin/sh` getting set by the `exit 1` command? – William Fleetwood Feb 16 '23 at 00:12
  • Yeah it runs @WilliamFleetwood. And honestly I have no idea. Unrelated: found this in the documentation (https://kubernetes.io/docs/concepts/workloads/controllers/job/) - "Jobs created before upgrading to Kubernetes 1.26 or before the feature gate JobTrackingWithFinalizers is enabled are tracked without the use of Pod finalizers. The Job controller updates the status counters for succeeded and failed Pods based only on the Pods that exist in the cluster. The contol plane can lose track of the progress of the Job if Pods are deleted from the cluster." That might be the problem idk – Jigglypuffer Feb 16 '23 at 00:38

2 Answers2

0

The pod terminated with a non-zero return code (from the exit 1), which is considered a failure.

Blender Fox
  • 4,442
  • 2
  • 17
  • 30
0

Your yaml file is missing some details like spec, api version, metadata etc., follow the below syntax it worked for me

apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: 
    - /bin/bash
    - -c
    - |
      exit 1

enter image description here

  • @Jigglypuffer is this helped you in answering your query? revert back if you need any additional information. Upvote or accept this solution so that it will be helpful for remaining community members. – Kranthiveer Dontineni Feb 22 '23 at 09:17
  • Hello sorry. I only gave the relevant details. My yaml file is valid. – Jigglypuffer Feb 25 '23 at 16:03
  • @Jigglypuffer I know that what I mean is that the `;` after your exit code is causing the issue remove that extra semicolon and it will work for you.. – Kranthiveer Dontineni Feb 26 '23 at 04:01