Resource Request/Limit in Kubernetes

Shashi Vishwakarma
3 min readOct 30, 2020

--

Hello There ,

Welcome back again on new post on Kubernetes tutorial. In todays article, we will focus on configuring resource requests and resource limits.

Each Pod requires certain amount of memory and cpu to function but some unusual circumstances Pod can behave weirdly and may consume entire cluster resource causing application and node failures. This behaviour can be controlled by below two configuration in Pod.

Requests : It is minimum amount of resource require for Pod to function. Kubernetes will look for available nodes to schedule pod based on requested resource.

Limits : It is maximum amount of resource required by Pod can consume.

In this article , we will accomplish following points.

  • Create a Pod without Resource Configuration
  • Perform CPU Stress on Container
  • Observe Resource Utilisation of Pod and Nodes.
  • Enable Resource Configuration in Pod
  • Observe Resource Utilisation of Pod and Nodes again.

Pre-requisite : Minikube Cluster

Docker Image : progrium/stress

Let’s Begin.

Step 1: Install Metric Server

Metrics server is require to measure resource utilisation in cluster. Execute below command to create metric server pods in cluster.

kubectl apply -f https://raw.githubusercontent.com/shashivish/kubernetes-example/master/pod-resources-example/components.yaml

You can verify installation using following commands.

kubectl get pods -n kube-system

Let’s quickly check whats current resource utilisation on nodes before we create stress pod.

You can observe , current CPU utilisation is quite low 7%. Now will stress on CPU to go high using our Pod.

Step 2: Create Stress Pod in Minikube Cluster

Alright , now we know how to check resource utilisation of nodes , we can go ahead create Pod which increases CPU utilisation drastically.

kubectl create deployment stresstest --image=progrium/stress --dry-run=client -o yaml > deployment.yaml

Edit deployment.yaml and following lines under container as shown in below example.

Your deployment.yaml container configuration should look like below.

Perfect..!! Now lets create pod in cluster

kubectl create -f deployment.yaml

Step 3: Observe Resource Utilisation of Nodes and Pod

After few second when Pod is in running state , check resource utilisation on node.

Similarly you can also check resource utilisation of each running pod.

resources: 
limits:
cpu: "1"
memory: "100Mi"
requests:
cpu: "0.5"
memory: "50Mi"

with above configuration , pod can request minimum 0.5 CPU and can consume upto 1 Core.

Save deployment.yaml file with above configuration and lets re-create container in cluster.

Step 5 : Observe Resource utilisation of Nodes and Pod

Cool , now let’s go ahead and check node as well as pod resource utilisation.

Resource utilisation has came down to half from 1898 → 1102 as we have limit configured to 1 Core which is maximum allowed by pod.

Conclusion : Resource utilisation play’s important role in managing pod as well as stability of overall cluster. As best a practice , developer must configured resource request limits while working with real environment.

Have a good day..!!

Keep learning , Keep Sharing ..!!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shashi Vishwakarma
Shashi Vishwakarma

Written by Shashi Vishwakarma

Senior Software/AI Engineer , Technical Writer

No responses yet

Write a response