[英]How to kill a docker container when it reaches set of memory usage or CPU limit
I have a docker container which running in a pod where I need to restart the pod / container when it exceeds memory usage or CPU limit. 我有一个在容器中运行的Docker容器,当容器/容器超过内存使用量或CPU限制时,我需要重新启动容器/容器。 How to configure it in docker file 如何在Docker文件中配置它
CPU and memory limits cannot be given when building a docker and it cannot be configured in Docker File
. 构建docker时无法给出CPU和内存限制,并且不能在Docker File
进行配置。 It is a scheduling problem. 这是一个调度问题。 You could run your docker with docker run
command with different flags to control resources. 您可以使用带有不同标志的docker run
命令运行docker,以控制资源。 See Docker Official Document for those control flags for docker run
. 有关docker docker run
那些控制标志,请参阅Docker Official Document 。
As your question is tagged with kubernetes
, there is kubernetes
way to limit your resources. 由于您的问题用kubernetes
标记,因此有kubernetes
方式可以限制您的资源。 You would want to add resources
in specs for those deployment
or pod
yaml. 您可能想在规范中为那些deployment
或pod
yaml添加resources
。 For example: 例如:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: your_deployment
labels:
app: your_app
spec:
replicas: 1
template:
metadata:
labels:
app: your_app
spec:
containers:
- name: your_container
image: your_image
resources:
limits:
cpu: "500m"
memory: "128Mi"
requests:
cpu: "250m"
memory: "64Mi"
...
requests
affects how docker pod is scheduled on nodes. requests
会影响docker pod在节点上的调度方式。 Memory limit
determines when the docker will be killed for OOM and cpu limit
determines how the container cpu usage will be throttled (The pod will not be killed). Memory limit
决定了何时为OOM而终止docker,而cpu limit
决定了如何cpu limit
容器cpu的使用(吊舱不会被终止)。
Meaning of cpu
is different for each cloud service providers. 每个云服务提供商的cpu
含义都不同。 For more information, please refer to manage compute resources for Kubernetes 有关更多信息,请参阅管理Kubernetes的计算资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.