How pod limits resource on kubernetes enforced when the pod exceed limits after pods is created ?

前提是你 提交于 2019-12-25 05:44:02

问题


I created Limits for the pods on kubernetes api server like this

apiVersion: v1
kind: LimitRange
metadata:
 name: limits
spec:
 limits:
  - default:
     cpu: 100m
     memory: 512Mi
    max:
     memory: 1024Mi
    type: pod

If I understand correctly,kubernetes would reject pod if the pod is exceeding user defined limits resource when the pod is created. so, I try to create a new pod which passed resource limits, then I try to consume resources reaching to the maximum limits resource, but it doesn't have any affected to the pod. Are the LimitsRanger and ResourceQuota plugin cover on this case or not if not how can I limit resource pods after it's already created?


回答1:


LimitRange is part of admission control; as you say, it has no effect once a Pod is running. To limit runtime resource consumption, use the Resources field in the Container.




回答2:


DavidO answer is correct, so I just want to explain a solution which solve this problem to others people whose facing same the problem with me.

you can limit running pod by adding the resources fields like this

"resources": {
          "limits": {
            "cpu": "100m",
            "memory": "50Mi"
           }
}

inside the array of container attributes in yaml or json file ,then I just create the rc and pods with file by

$ kubectl create -f filename.yaml

that's all credit: DavidO



来源:https://stackoverflow.com/questions/32034827/how-pod-limits-resource-on-kubernetes-enforced-when-the-pod-exceed-limits-after

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!