I have a Kubernetes cron job that gets an OOMKilled (Out of Memory) message when running. This specific cron job runs once a day. The node itself has 4 GB of RAM.
Found somewhere that said the default for a cron job is 100 MB? Where can I view or change the default for Kubernetes cron jobs?
You can just add resources and limits to that job so you can prevent it from being OOM killed. One thing to note is how resources and limits work. I have explained some scenarios in this answer on Stack. It is worthy to check the official documentation to avoid common mistakes and also CPU and Memory resources/limits work a little bit different.
About the default values of resources and limits it depends on where is your cluster. For example in my kubeadm I do not have any resources or limits by default in default
namespace:
kubectl describe ns default
Name: default
Labels: <none>
Annotations: <none>
Status: Active
No resource quota.
No resource limits.
And this is for GKE:
So your choice is to set up Requests and Limits for your namespace or just add it into the Job spec, like in this example:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: testing-hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hi-there
image: busybox
args:
- /bin/sh
- -c
- date; echo "Hello, World!"
resources:
requests:
cpu: "100Mi"
limits:
cpu: "100Mi"
restartPolicy: OnFailure
Also usually you would just set resources and limits per namespace as it is described here.