Kubernetes resources and limits

Amit Cohen
3 min readDec 21, 2022

--

As part of the job of Kubernetes admin, you are responsible for checking if developers are adhering to the best practice standards and configuring workloads correctly. One of those best practices is whether they have defined resource requests and limits for their workloads. Let us understand what are resources requests and limits before diving in, when you see a workload configure without them you should notify the developer to modify his YAML file.

Resource Requests

Some applications may need more CPU and memory resources than others to make sure your application has enough resources in its pod you should define resource requests for each of your containers.

Resource Limits

The resource limit handles noisy neighbors, when a pod starts to consume resources with no limits, this can affect other pods’ performance. An example of resources could be CPU and memory consumption, the result affects pod scheduling that could be avoided. You will be able to solve it by setting limits in addition to resource requests.

Once the use cases are clear for resource requests and resource limits let’s explore and see some YAML examples with definitions of container resources inside the pod. First, you need to decide how many resources will your application need, In most cases, your apps will require average CPU and RAM but you may have apps that are CPU intensive. Or memory (DB like Redis) that needs more memory space, for these you want to adjust the resources. The main thing to remember is that not all apps are the same. And when they need more or fewer resources it’s always good to explicitly define them.

As you can see above under the resources you can find the requests I set and their limits. In simple words, the app can not consume more than the 128M RAN and 500m CPU.

Querry for resources

Now let’s go one step beyond that, what happens on a large scale when you have hundreds of deployments running and you want to analyze which pods have explicit resources request and limits? for that, you should run the following kubectl command and the output below it.

kubectl get pod -o jsonpath=”{range .items[*]} {.metadata.name}{.spec.containers[*].resources}{‘\n’}”

When a node runs out of resources and has to evict one of the pods it will evict the pod that does not have an explicit resource request first.

Join my Linkedin

--

--

Amit Cohen
Amit Cohen

Written by Amit Cohen

A product leader with exceptional skills and strategic acumen, possessing vast expertise in cloud orchestration, cloud security, and networking.

No responses yet