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

标签 kubernetes kubernetes-pod docker-container

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/

相关文章:

python-3.x - 无法在运行 Sparkapplication 的 pod 上使用 configmap 挂载配置文件

docker - Kubernetes 节点设备端口 (USB) 映射到 POD?或者Swarm服务--设备映射

laravel-5 - Laravel Redis php_network_getaddresses : getaddrinfo failed: Name or service not known [tcp://redis:6379]

docker - 连接多个Docker应用

kubectl - 为什么端口转发到 headless (headless)服务总是路由到同一个 pod?

docker - 当多个容器在同一主机上运行时,docker 是否会重用图像?

kubernetes - 即使配置没有更改,如何重新启动 Pod

go - K8s Go 客户端库无法在 go get 上找到包

nginx - Kubernetes NodePort不监听

kubernetes - kubectl排空是先移除 pods 还是先创建 pods