[英]Is it possible to enforce a hard memory limit on pods?
A Container can exceed its memory request [...].
容器可以超过其 memory 请求 [...]。 If a Container allocates more memory than its limit, the Container becomes a candidate for termination.
如果 Container 分配的 memory 超过其限制,则该 Container 成为终止的候选者。
From the documentation I understand setting resource limits can't limit the pod's memory usage.从文档中我了解到设置资源限制不能限制 pod 的 memory 使用。
I have a container that will always use up all the memory available to it, but will function also with smaller amounts of memory.我有一个容器,它总是会用完所有可用的 memory,但 function 也会用少量的 memory。 Is there any way I can set a hard limit to the amount of memory available to the pod running the container?
有什么方法可以对运行容器的 pod 可用的 memory 数量设置硬限制?
Since it is possible in Docker I hope there is also a way to achieve this in Kubernetes, but I could not find a way to do this.由于在 Docker 中是可能的,我希望在 Kubernetes中也有办法实现这一点,但我找不到这样做的方法。
It is possible with standard request
and limits
.标准
request
和limits
是可能的。 First see the official documentation page :首先查看官方文档页面:
When you specify a Pod , you can optionally specify how much of each resource a Container needs.
当你指定一个Pod时,你可以选择指定一个容器需要多少每个资源。 The most common resources to specify are CPU and memory (RAM);
最常见的指定资源是 CPU 和 memory (RAM); there are others.
还有其他人。
When you specify the resource request for Containers in a Pod, the scheduler uses this information to decide which node to place the Pod on.
当您为 Pod 中的容器指定资源请求时,调度程序会使用此信息来决定将 Pod 放置在哪个节点上。 When you specify a resource limit for a Container, the kubelet enforces those limits so that the running container is not allowed to use more of that resource than the limit you set.
当您为 Container 指定资源限制时,kubelet 会强制执行这些限制,以便正在运行的容器不允许使用超过您设置的限制的资源。 The kubelet also reserves at least the request amount of that system resource specifically for that container to use.
kubelet 还至少保留了该系统资源的请求量,专门供该容器使用。
In kubernetes, if you want to reserve a minimum amount of memory specifically for a given container, you should use request
.在 kubernetes 中,如果您想专门为给定容器预留最小数量的 memory,您应该使用
request
。 If, on the other hand, you want to force the container to not be able to use more memory than you specify, you must use the limit
.另一方面,如果你想强制容器不能使用比你指定的更多的 memory,你必须使用
limit
。
Here is an example:这是一个例子:
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 500m
memory: 2Gi
See also this great article about setting the right requests and limits in Kubernetes.另请参阅这篇关于在 Kubernetes 中设置正确请求和限制的精彩文章。
Normal requests and limits should work.正常的请求和限制应该有效。 Documentation might be misleading.
文档可能具有误导性。 Pods will not go beyond the memory limit, if they try to it will cause an OOM and crash(restarted).
Pod 不会 go 超出 memory 限制,如果他们尝试这样做会导致 OOM 和崩溃(重新启动)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.