DrNutsu
DrNutsu

Reputation: 476

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

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?

Upvotes: 0

Views: 2901

Answers (2)

DrNutsu
DrNutsu

Reputation: 476

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

Upvotes: 3

DavidO
DavidO

Reputation: 1763

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.

Upvotes: 5

Related Questions