简体   繁体   English

K8S中的Java OOM自动堆转储文件名

[英]Java OOM Automatic Heap Dump File Name in K8S

An answer to this question is available at https://stackoverflow.com/a/34077693/1525813 but not from a Kubernetes perspective.这个问题的答案可以在https://stackoverflow.com/a/34077693/1525813找到,但不是从 Kubernetes 的角度来看。

For my k8s app, I specify the JVM options as an environment variable in the k8s YAML (below).对于我的 k8s 应用程序,我在 k8s YAML(如下)中将 JVM 选项指定为环境变量。 This has been giving issues where the pod crashes on container start-up (running Linux) as the command substitution isn't working as expected.由于命令替换未按预期工作,这导致容器启动(运行 Linux)时 pod 崩溃的问题。

ENV VAR环境变量

spec:
  template:
    spec:
      containers:
      - name: myapp
        command: [ '/bin/sh', '-c' ]
        args:
          - exec java $JVM_OPTS -jar myapp.jar
#         - exec startup.sh # For few other apps
        env:
        - name: JVM_OPTS
          value: >-
            -XX:+HeapDumpOnOutOfMemoryError
            -XX:HeapDumpPath=/logs/heapdump/hd_$(date +%F_%H-%M-%S)_pid$$.hprof
            -XX:+CrashOnOutOfMemoryError
            -XX:OnError=/scripts/threaddump.sh
            -XX:ErrorFile=/logs/error/hs_err_$(date +%F_%H-%M-%S)_pid$$.log
            -Xlog:gc*=debug:file=/logs/gc/gc_%t_pid%p.log:time,uptimemillis,pid,tid,level,tags

ERROR LOGS on container startup容器启动时的错误日志

Error: Could not find or load main class +%F_%H-%M-%S)_pid$.hprof"
Caused by: java.lang.ClassNotFoundException: +%F_%H-%M-%S)_pid$.hprof"

What am I missing here?我在这里错过了什么?


SUB-QUESTION子问题

The earlier config was -XX:HeapDumpPath=/logs/heapdump/hd_%t_pid%p.hprof which was not interrupting the container start-up but the heap dump file was being created with the name hd_%t_pid%p.hprof ie %t and %p were not being substituted for -XX:HeapDumpPath but were substituted for -Xlog:gc* .较早的配置是-XX:HeapDumpPath=/logs/heapdump/hd_%t_pid%p.hprof ,它不会中断容器启动,但会创建名为hd_%t_pid%p.hprof的堆转储文件,即%t%p没有被替换为-XX:HeapDumpPath但被替换为-Xlog:gc*

What could be the cause of discrepancy here?此处差异的原因可能是什么?

Thanks谢谢

See for details https://github.com/kubernetes/kubernetes/issues/112645详情见https://github.com/kubernetes/kubernetes/issues/112645

I added these values for JVM_OPTS in a shell script and used it to invoke the JAR.我在 shell 脚本中为 JVM_OPTS 添加了这些值,并使用它来调用 JAR。 Then invoked the script from the k8s YAML args.然后从 k8s YAML args 调用脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM