gpt4 book ai didi

kubernetes - 是否可以对 Pod 实现硬内存限制?

转载 作者:行者123 更新时间:2023-12-05 08:04:02 26 4
gpt4 key购买 nike

A Container can exceed its memory request [...]. If a Container allocates more memory than its limit, the Container becomes a candidate for termination.

来自 the documentation我了解设置资源限制不能限制 pod 的内存使用。

我有一个容器,它总是会用完所有可用的内存,但也可以使用较少的内存。有什么方法可以对运行容器的 pod 的可用内存量设置硬性限制?

因为它is possible in Docker我希望在 Kubernetes 中也有一种方法可以实现这一点,但我找不到实现这一点的方法。

最佳答案

标准的requestlimits 是可能的。先看official documentation page :

When you specify a Pod, you can optionally specify how much of each resource a Container needs. The most common resources to specify are CPU and 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. 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. The kubelet also reserves at least the request amount of that system resource specifically for that container to use.

在 kubernetes 中,如果你想专门为给定的容器保留最小量的内存,你应该使用 request。另一方面,如果您想要强制容器使用的内存不能超过您指定的内存,则必须使用 limit

这是一个例子:

resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 500m
memory: 2Gi

另见 this great article关于在 Kubernetes 中设置正确的请求和限制。

关于kubernetes - 是否可以对 Pod 实现硬内存限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70362201/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com