1

On a OpenShift 3.11 running app, I am trying to get a HeapDump because I suspect an OOM on my pods.

My app runs on 14 replicas and i want to append the following configuration to the Java Options

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=file:///my/path/jdump/

the path is on an external mounted volume.

Now I know that the default filename will be

java_pid1.hprof 

but from a

ps -ef | grep java

i noticed that most the pods use the same pid for the process, and I fear that if a OOM occurs on more than one pod at the same time I will get a problem with a contemporary access and write to the file.

Is there a way to parametrize the filename? I imagine something like

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=file:///my/path/jdump/{$podname}_dump.href

thanx a lot for your kind answers

natrium
  • 55
  • 1
  • 8

1 Answers1

2

You can expose a pod name as env variable and then use it in you command, i.e.

      command: [ "/bin/java"]
      args:
      - "-jar"
      - "your.jar"
      - "-XX:+HeapDumpOnOutOfMemoryError"
      - "-XX:HeapDumpPath=file:///my/path/jdump/$(MY_POD_NAME)_dump.href"
      env:
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name

Mind the $(MY_POD_NAME) syntax - reference https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#use-environment-variables-to-define-arguments

Exposing fields as env vars: https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables

Andrew
  • 3,912
  • 17
  • 28