简体   繁体   English

Kubernetes 是否应该在内存不足时重新启动我的 JVM 应用程序?

[英]Should Kubernetes restart my JVM app when going out of memory?

We have an application deployed on Kubernetes.我们在 Kubernetes 上部署了一个应用程序。 One of the services is an app running in the JVM.其中一项服务是在 JVM 中运行的应用程序。

Our application is faulty, it consumes to much memory.我们的应用程序有问题,它消耗了太多内存。 We are hitting the limit set in the Replication Controller, which makes it restart the pod.我们达到了复制控制器中设置的限制,这使得它重新启动 pod。

Is it a good idea to use the replication controller for this?为此使用复制控制器是个好主意吗? Or is it a better idea to limit the memory on the JVM (set it to something below the replication controller limit) and use something else inside the pod to restart our application?还是限制 JVM 上的内存(将其设置为低于复制控制器限制的值)并使用 pod 内的其他内容重新启动我们的应用程序是否更好?

If the JVM would stop with an out-of-memory exception, I could use memory dumps written by the JVM.如果 JVM 会因内存不足异常而停止,我可以使用 JVM 写入的内存转储。 Now I'm blind as to what occupied the memory.现在我对内存中的内容一无所知。

Thank you for your reply!感谢你的回复!

In fact this is not a responsibility of Deployment / ReplicationController.事实上,这不是 Deployment/ReplicationController 的责任。 The restarts are handled within Pod it self.重新启动是在 Pod 内部处理的。 As for handling memory, this is not a trivial issue and you should control it on both levels (things like heap sizes etc.) so that your app avoids hitting the limit, but if it does go awall, limits on pod will handle it, and that is perfectly ok (specially if you run more then one pod so you have HA).至于处理内存,这不是一个微不足道的问题,您应该在两个级别(如堆大小等)上控制它,以便您的应用程序避免达到限制,但如果它确实出现了问题,pod 上的限制将处理它,这完全没问题(特别是如果你运行了多个 Pod,那么你就有了 HA)。

The thing here is, that is is a bit tricky to tune memory limits well, and probably can be done best with trial and error + monitoring pod/container metrics (Prometheus/Grafana to the rescue :) ).这里的问题是,要很好地调整内存限制有点棘手,并且可能可以通过反复试验+监控 pod/容器指标(Prometheus/Grafana 来救援 :) 来做到最好)。

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

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