简体   繁体   English

是否可以对 pod 实施硬性 memory 限制?

[英]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 .标准requestlimits是可能的。 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.

相关问题 Kubernetes如何执行容器的内存限制? - How does Kubernetes enforce the memory limit for a container? 在 Kubernetes 中获取 CPU 和 Memory 硬限制计数 - Getting CPU and Memory hard limit count in Kubernetes 为气流将创建以在 Kubernetes 中运行任务的 Pod 分配内存请求和限制 - Allocate memory request and limit for the pods that airflow will create to run tasks in kubernetes 是否可以在一个部署中创建具有不同资源限制的Pod? - It's possible to create pods with different resources limit in one deployment? Grafana 仪表板中的 Kubernetes pod 显示 memory 与 Current、Requested、Limit 和 Cache 的使用情况。 缓存表示什么? - Kubernetes pods in Grafana dashboard show memory usage with Current, Requested, Limit and Cache. What does Cache indicate? 在 kubernetes 中创建 pod 时 CPU 和内存的请求和限制的默认值是多少? - What is the default value for request and limit for both CPU and memory while creating pods in kubernetes? 有可能吗?如果总是失败,如何限制kubernetes作业以创建最大数量的Pod? - Is it possible, and how to limit kubernetes job to create a maxium number of pods if always fail? 为 Kubernetes 中的 Pod 分配或限制资源? - Allocate or Limit resource for pods in Kubernetes? 限制每个节点的 Pod 数量 - Limit the number of pods per node 我们如何根据 memory 利用率参数限制给定工作节点 (VM) 中的 pod 数量并触发节点扩展 - How can we limit the number of pods in a given worker node (VM) based on memory utilization parameter and trigger scaling of nodes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM