0

Kubernetes pod getting terminated and marked as OOMKilled. Below is my cronjob yaml file:

kind: CronJob
metadata:
name: test-cron
spec:
schedule: "30 2 1 * *"
concurrencyPolicy: Forbid
jobTemplate:
  spec:
    backoffLimit: 1
    template:
      spec:
        containers:
          - name: test-container
            image: <image>
            resources:
              limits:
                memory: 10240Mi
                cpu: 4000m
                ephemeral-storage: 2Gi
              requests:
                memory: 10240Mi
                cpu: 4000m
                ephemeral-storage: 2Gi
            args:
              - java
              - -cp
              - /jars/*
              - -Xmx9g
              - -Xms9g
              - -XX:+UnlockCommercialFeatures
              - -XX:+FlightRecorder
              - -Dcom.sun.management.jmxremote
              - -Dcom.sun.management.jmxremote.port=9002
              - -Dcom.sun.management.jmxremote.authenticate=false
              - -Dcom.sun.management.jmxremote.ssl=false
              - com.test.app.TestApplication
        restartPolicy: Never

I am not getting OutOfMemoryError in my java application. One of the reasons can be pod is using high memory than the limit mentioned in the yaml. But how's that possible because Xmx set is 9GB and if heap usage tries to go above 9GB then my application should throw OOM error.

One thing I tried doing was increasing the pod memory request and limit to 15GB basically now there is big difference between Xmx and pod memory request/limit. This time my pod ran successfully. Why did it work?

Nishant Middha
  • 302
  • 1
  • 9
  • note that Xmx affects only the heap, while JVM uses memory outside the heap for other purposes as well (metaspace, code cache, etc.) so we always recommend setting xmx and xms to be not more than 50% of your requests memory. so if your memory requests are 10Gi your xmx and xms should be 5G – Ahmed Zidan Nov 06 '22 at 12:56

1 Answers1

0

issue looks to be with the memory limit assigned to the pod.

              - -Xmx9g
              - -Xms9g

look at the above arguments, the java process is going to consume upto 9gb memeroy but the maximum memory allocated to the pod is just 1gb. Hence the pod is getting crashed as the memory limit is not sufficient. You need to adjust the memory request and ,limits details.

P Ekambaram
  • 15,499
  • 7
  • 34
  • 59