How pod limits resource on kubernetes enforced whe

2019-09-05 05:16发布

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?

2条回答
再贱就再见
2楼-- · 2019-09-05 05:35

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.

查看更多
我想做一个坏孩纸
3楼-- · 2019-09-05 05:44

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

查看更多
登录 后发表回答