Limit Range & Quota

Limit Range & Quota

LimitRange is an API object that limits resource usage per container or Pod in a Namespace It uses three relevant options:

type: specifies whether it applies to Pods or containers defaultRequest: the default resources the application will request default: the maximum resources the application can use

apiVersion: v1 
kind: LimitRange 
metadata:
  name: mem-limit-range
  namespace: limited
spec:
  limits:
  - default:
      memory: 125Mi
    defaultRequest:
      memory: 100Mi
    max: 
      memory: 500Mi 
    type: Container

This will setup a memory limit on containers

I will create a specific deployment and i will set up high memory usage to exceed limit range and see what happen

Let’s see what happend

The pod is not created, and if i check the replicaset (since it is the close on to the pod)

The ReplicSet failed to create the pod becuse it’s demands are higher than what the limit range set

Quota

Quota is an API object that limits total resources available in a Namespace If a Namespace is configured with Quota, applications in that Namespace must be configured with resource settings in pod.spec.containers.resources

Where the goal of the LimitRange is to set default restrictions for each application running in a Namespace, the goal of Quota is to define maximum resources that can be consumed within a Namespace by all

I will define a resource quota manifest file that wil be bound to a new name space called ‘team’

This will limit resources of memory and cpu on the team namespcae

I will create a deployment

So when i try to scale it up to 7 replicas, it wont, because each pod is requesting 100Mi from memory and 5 pods will be the maximum and that’s why i have only 5 pods