Shashikant shah

Thursday, 25 April 2024

Resource Requests and Limits


 If you schedule a large application in a node which has limited resources, then it will soon lead to OOM (out of memory) or others and will lead to downtime.



Requests and Limits are two ways in which we can control the amount of resource that can be assigned to a pod (resource like CPU and Memory)

Requests:  Guaranteed to get.

Limits:  Makes sure that the container does not take node resources above a specific value.


i)Kubernetes Scheduler decides the ideal node to run the pod depending on the requests and limits.

ii)If your POD requires 8GB of RAM, however, there are no nodes within your cluster which has 8GB RAM, then your pod will never get scheduled.

1. default pods for no limits.

# kubectl get pods -o wide

# kubectl describe node worker02


# vim requests-limits.yaml

apiVersion: v1

kind: Pod

metadata:

  name: labs-pod

spec:

  containers:

  - name: labs-container

    image: nginx

    resources:

      requests:

        memory: "640Mi"

        cpu: "0.5"

      limits:

        memory: "12800Mi"

        cpu: "1"

# kubectl apply -f requests-limits.yaml

# kubectl get pods -o wide

# kubectl describe nodes worker01


Namespace: The Kubernetes namespace in which the pod resides. In this case, the pod is in the default namespace.

Name: The name of the pod. Here, the pod is named labs-pod.

CPU Requests: The amount of CPU resources that the pod requests from the cluster. In this case, the pod requests 500 milliCPU (millicores), which is equivalent to 0.5 CPU cores or 50% of a single CPU core.

CPU Limits: The maximum amount of CPU resources that the pod is allowed to consume. Here, the pod has a CPU limit of 1 CPU core, which is equivalent to 100% of a single CPU core.

Memory Requests: The amount of memory resources that the pod requests from the cluster. In this case, the pod requests 640 megabytes of memory.

Memory Limits: The maximum amount of memory resources that the pod is allowed to consume. Here, the pod has a memory limit of 12800 megabytes.

Age: The age of the pod, indicating how long it has been running.






No comments:

Post a Comment