如何使Kubernetes不终止消耗过多内存的Pod。

huangapple go评论85阅读模式
英文:

How to make kubernetes not kill pods that consume too much memory

问题

我有一个带有容器内存限制的Kubernetes作业。例如:

apiVersion: v1
kind: Job
metadata:
 name: example-job
spec:
 containers:
 - name: example-container-name
   image: someimage
   resources:
     limits:
       memory: "1Gi"

然而,如果容器消耗的内存超过1GB,它会被OOMKILLED。我无法控制我的应用程序使用多少内存,有没有办法阻止Kubernetes杀死Pod,而是限制其内存使用?我希望行为类似于个人计算机 - 如果使用的内存太多,一切都会变得更慢(由于例如交换),但通常不会被操作系统杀死。

英文:

I have a Kubernetes job with container memory limits. For e.g:

apiVersion: v1
kind: Job
metadata:
 name: example-job
spec:
 containers:
 - name: example-container-name
   image: someimage
   resources:
     limits:
       memory: "1Gi"

However, if the container consumes more memory than 1GB it gets OOMKILLED. I can't control how much memory my application takes, is there a way to prevent Kubernetes kill the pod and instead limit its memory usage? I want the behavior to be similar to that of a personal computer - if you use too much memory everything becomes slower (due to swapping for e.g), but the process is not killed by the OS normally.

答案1

得分: 2

发生这种情况是因为您的应用程序占用了超过1 GB的内存,而您将您的Pod的最大内存限制设置为1 GB,所以当您的应用程序消耗超过1 GB的内存时,Kubernetes会终止您的应用程序,因此最佳操作是使您的应用程序的资源使用更有效,或者增加您的限制。

额外提示:如果您的Pod中有多个容器,您需要考虑其他容器的内存使用情况。如果您有一个sidecar容器或mutating webhook,就会发生这种情况。

英文:

It happened because your application took more than 1 GB memory, and you did limit your pod with 1 GB max, so when your application consumes more than 1 GB Memory your application will be killed by Kubernetes, so the best action is make your application resource usage more effective or increase your limit.

Additional tips: if you had more than 1 container in your pod you need to consider the other container memory usage. it happens if you have a sidecar container or mutating webhook.

答案2

得分: 0

通过在您的描述符中指定资源限制,您正在告诉Kubernetes,如果超出了该限制,就要终止您的Pod。因此,正如其他人所说,要么移除限制,提高限制,要么使您的代码更加高效。这是您唯一的选择。

英文:

By specifying the resource limits in your descriptor, you are telling Kubernetes to kill your pod if you exceed that limit. So as other people have said, remove the limit, raise the limit or make your code more efficient. Those are the only options you have.

huangapple
  • 本文由 发表于 2023年6月26日 15:11:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554306.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定