Search code examples
javacontainersdocker-swarmkubernetes-helmkubernetes-jobs

How to intentionally fail a job in kubernetes?


I have an image of java code that does database validation and the job uses that image. I want the job to intentionally fail when the database validation fails. Is there any way to do the same?


Solution

  • A Kubernetes job is just a contrainer running. As with any container, the final exit code determines if the run was successful or not. So, to make your job fail you need to exit with a code other than 0.

    How would you do this in Java?

    System.exit(1)
    

    How would you do this in Bash scripting?

    exit 1
    

    How would you do this in Node.js?

    process.exit(1)
    

    How would you do this in Python/PHP?

    exit(1)
    

    How would you do this in Go?

    os.Exit(1)