Questions tagged [kubernetes-jobs]

139 questions
162
votes
9 answers

How to automatically remove completed Kubernetes Jobs created by a CronJob?

Is there a way to automatically remove completed Jobs besides making a CronJob to clean up completed Jobs? The K8s Job Documentation states that the intended behavior of completed Jobs is for them to remain in a completed state until manually…
Josh Newman
  • 1,645
  • 2
  • 11
  • 6
115
votes
7 answers

Tell when Job is Complete

I'm looking for a way to tell (from within a script) when a Kubernetes Job has completed. I want to then get the logs out of the containers and perform cleanup. What would be a good way to do this? Would the best way be to run kubectl describe job…
russt
  • 1,548
  • 2
  • 14
  • 16
69
votes
5 answers

How to run containers sequentially as a Kubernetes job?

I'm trying to replace my legacy job scheduler with Kubernetes job and wondering how to write sequential jobs as a Kubernetes job. First, I wrote the following script to execute job1 and job2 in the written order but it didn't work as I…
k-kawa
  • 1,289
  • 2
  • 11
  • 18
52
votes
3 answers

Kubernetes - how to run job only once

I have a job definition based on example from kubernetes website. apiVersion: batch/v1 kind: Job metadata: name: pi-with-timeout-6 spec: activeDeadlineSeconds: 30 completions: 1 parallelism: 1 template: metadata: name: pi …
esio
  • 1,592
  • 3
  • 17
  • 30
47
votes
5 answers

Wait for kubernetes job to complete on either failure/success using command line

What is the best way to wait for kubernetes job to be complete? I noticed a lot of suggestions to use: kubectl wait --for=condition=complete job/myjob but i think that only works if the job is successful. if it fails, i have to do something…
ruazn2
  • 745
  • 2
  • 8
  • 15
35
votes
4 answers

Pods stuck in PodInitializing state indefinitely

I've got a k8s cronjob that consists of an init container and a one pod container. If the init container fails, the Pod in the main container never gets started, and stays in "PodInitializing" indefinitely. My intent is for the job to fail if the…
31
votes
4 answers

kubectl list / delete all completed jobs

I'm looking for a kubectl command to list / delete all completed jobs I've try: kubectl get job --field-selector status.succeeded=1 But I get: enfield selector "status.succeeded=1": field label "status.succeeded" not supported for batchv1.Jobter…
29
votes
4 answers

"kubectl create job" from CronJob fails with "error: unknown object type *v1beta1.CronJob"

I have a Kubernetes cluster with following versions: $ kubectl version Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.1", GitCommit:"632ed300f2c34f6d6d15ca4cef3d3c7073412212", GitTreeState:"clean",…
17
votes
3 answers

How to set a time limit for a Kubernetes job?

I'd like to launch a Kubernetes job and give it a fixed deadline to finish. If the pod is still running when the deadline comes, I'd like the job to automatically be killed. Does something like this exist? (At first I thought that the Job spec's…
Bosh
  • 8,138
  • 11
  • 51
  • 77
10
votes
2 answers

What is difference between Kubernetes Jobs & Deployments

I see that Kubernetes Job & Deployment provide very similar configuration. Both can deploy one or more pods with certain configuration. So I have few queries around these: Is the pod specification .spec.template different in Job & Deployment? What…
Mukund Jalan
  • 1,145
  • 20
  • 39
8
votes
1 answer

Error: UPGRADE FAILED: pre-upgrade hooks failed: timed out waiting for the condition

I am testing a pre-upgrade hook which just has a bash script that prints a string and sleep for 10 mins. When I run helm upgrade, it ran for some time and exited with the error in the title. I used kubectl to check the job and it was still running.…
Fan Zhang
  • 139
  • 1
  • 2
  • 3
7
votes
2 answers

How do I manually trigger a kubernates job (not a cron) in k8s

I have sample k8s job as soon as you do kubectl apply the job gets triggered and the pods are created . How to control the pod creation? apiVersion: batch/v1 kind: Job metadata: name: pi-with-timeout spec: backoffLimit: 5 …
6
votes
2 answers

Create or update existing postgres db container through kubernetes job

I have a Postgres DB container which is running in a Kubernetes cluster. I need to write a Kubernetes job to connect to the Postgres DB container and run the scripts from SQL file. I need to understand two things here commands to run SQL script…
Pandit Biradar
  • 1,777
  • 3
  • 20
  • 35
5
votes
1 answer

Restart a Kubernetes Job or Pod with a different command

I'm looking for a way to quickly run/restart a Job/Pod from the command line and override the command to be executed in the created container. For context, I have a Kubernetes Job that gets executed as a part of our deploy process. Sometimes that…
Martin Melka
  • 7,177
  • 16
  • 79
  • 138
5
votes
1 answer

Can manually triggered cron jobs respect the concurrencyPolicy?

So I've a cron job like this: apiVersion: batch/v1beta1 kind: CronJob metadata: name: my-cron-job spec: schedule: "0 0 31 2 *" failedJobsHistoryLimit: 3 successfulJobsHistoryLimit: 1 concurrencyPolicy: "Forbid" startingDeadlineSeconds:…
natschz
  • 1,007
  • 10
  • 23
1
2 3
9 10