Increment heap memory in a container with Kubernetes

9/21/2021

I'm facing with a issue in my spring boot service. After deploy it on kubernetes I have a Java Heap Space. I have set the next environment configuration on my deployment.yaml:

  containers:
    - name: {{ .Chart.Name }}
      image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
      imagePullPolicy: {{ .Values.image.pullPolicy }}
      env:
        - name: JAVA_OPTS
          value: "-Xms512M -Xmx512M -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1"

But after make a new deployment I'm still having the same issue because this way hasn't had effect. I have gone inside of my image and I have seen that the heap memory is around 200MB.

My image is working under openjdk 11. Any idea about why is not working correctly?

Thank you.

-- nole
deployment
kubernetes
spring
spring-boot

1 Answer

9/21/2021

I'm guessing you just set that env variable, which does nothing, you need to add it to your RUN/ENTRYPOINT java command in your Dockerfile or as args for your kubernetes command.

Most likely something like

ENTRYPOINT java $JAVA_OPTS -jar <path to your jar>

would work

-- somethingsomething
Source: StackOverflow