Questions tagged [kubernetes-cronjob]
301 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
128
votes
7 answers
Disabling cronjob in Kubernetes
I have scheduled an application to run as a CronJob in Kubernetes. When there is a code change, I'm also changing the image of the CronJob.
I'm looking for an option where I can disable the currently running CronJob and deploy a new CronJob with the…

Jasmitha Meka
- 1,387
- 3
- 10
- 11
49
votes
6 answers
Cron Jobs in Kubernetes - connect to existing Pod, execute script
I'm certain I'm missing something obvious. I have looked through the documentation for ScheduledJobs / CronJobs on Kubernetes, but I cannot find a way to do the following on a schedule:
Connect to an existing Pod
Execute a script
Disconnect
I have…
user1262516
43
votes
1 answer
What does Kubernetes cronjobs `startingDeadlineSeconds` exactly mean?
In Kubernetes cronjobs, It is stated in the limitations section that
Jobs may fail to run if the CronJob controller is not running or broken for a span of time from before the start time of the CronJob to start time plus startingDeadlineSeconds,…

Hesham Massoud
- 1,550
- 1
- 11
- 17
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…

Anderson
- 531
- 1
- 5
- 8
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",…

Gautam S. K. Singhania
- 511
- 1
- 4
- 9
27
votes
1 answer
no matches for kind "CronJob" in version "batch/v1"
I use Kubernetes which v1.19.7, when I run the CronJob sample
apiVersion: batch/v1
kind: CronJob
metadata:
name: express-learn-cronjob
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
…

seven
- 579
- 1
- 5
- 9
24
votes
2 answers
access logs in cron jobs kubernetes
I'm running a CronJob in kubernetes, the jobs complete successfully and I log output to the log file inside (path: storage/logs) but I cannot access that file due to the container being in a completed state.
Here is my job yaml:
apiVersion:…

Jack
- 1,162
- 3
- 12
- 27
22
votes
1 answer
Call endpoint from Kubernetes Cron Job
I have a webapp running in a Docker-container in a Kubernetes cluster. The app has an endpoint I want to be called periodically. The app runs at multiple nodes/pods, and it is important that only one node performs the task initiated by the endpoint.…

user1119371
- 417
- 2
- 7
- 13
21
votes
2 answers
How to schedule a cronjob which executes a kubectl command?
How to schedule a cronjob which executes a kubectl command?
I would like to run the following kubectl command every 5 minutes:
kubectl patch deployment runners -p…

Chillax
- 4,418
- 21
- 56
- 91
14
votes
2 answers
Disable Istio sidecar injection to the job pod
How to disable Istio sidecar injection for the Kubernetes Job?
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: pod-restart
spec:
concurrencyPolicy: Forbid
schedule: '0 8 * * *'
jobTemplate:
metadata:
annotations:
…

Jonas
- 4,683
- 4
- 45
- 81
13
votes
1 answer
Is there a kubernetes cronjob kind which allows multiple schedules for a single container image?
If one has an image with a number of different executables, is it possible to have multiple cron entries with different commands that run at different times in the same kubernetes deployment.
e.g. For some single container image named "jolly-roger",…

Rich
- 3,781
- 5
- 34
- 56
12
votes
1 answer
Set retention policy for Pods created by Kubernetes CronJob
I understand that Kubernetes CronJobs create pods that run on the schedule specified inside the CronJob. However, the retention policy seems arbitrary and I don't see a way where I can retain failed/successful pods for a certain period of time.

gabbar0x
- 4,046
- 5
- 31
- 51
11
votes
1 answer
Time-based scaling with Kubernetes CronJob: How to avoid deployments overriding minReplicas
I have a HorizontalPodAutoscalar to scale my pods based on CPU. The minReplicas here is set to 5:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-web
spec:
scaleTargetRef:
apiVersion: apps/v1
kind:…

MDalt
- 1,681
- 2
- 24
- 46
11
votes
2 answers
Scheduled restart of Kubernetes pod without downtime
I have 6 replicas of a pod running which I would like to restart\recreate every 5 minutes.
This needs to be a rolling update - so that all are not terminated at once and there is no downtime. How do I achieve this?
I tried using cron job, but seems…

Chillax
- 4,418
- 21
- 56
- 91