Shashikant shah

Thursday, 25 April 2024

Pods Resource Requests and Limits


 Pod-level Requests & Limits.

These are set inside a pod specification and control how each container requests and consumes resources.

Purpose:

1. Ensures a container gets minimum resources (requests).

2. Restrict a container’s maximum resource usage (limits).

3. Only applies to individual containers/pods, not the whole namespace.


Behavior of Limit resource issue.

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

b) If a pod requests more CPU than limits.cpu, Kubernetes slows it down (throttling).

c) If a pod uses more memory than limits.memory, Kubernetes stops and restarts it (OOMKill).



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


Defines a Kubernetes Pod named labs-pod with a single container running Nginx, and it sets resource requests and limits.

# 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