KodeKloud Engineer Kubernetes Tasks

Level 1-4. Set Limits for Resources in Kubernetes

·

2 min read

KodeKloud Engineer Kubernetes Tasks

Photo by Growtika on Unsplash

Question 4:

Recently some of the performance issues were observed with some applications hosted on the Kubernetes cluster. The Nautilus DevOps team has observed some resource constraints, where some of the applications are running out of resources like memory, CPU, etc., and some of the applications are consuming more resources than needed. Therefore, the team has decided to add some limits for resource utilization. Below you can find more details.

Create a pod named httpd-pod and a container under it named httpd-container, use httpd image with the latest tag only and remember to mention the tag i.e httpd:latest, and set the following limits:

Requests: Memory: 15Mi, CPU: 100m

Limits: Memory: 20Mi, CPU: 100m

Note: The kubectl utility on jump_host has been configured to work with the Kubernetes cluster.

Solution :

- Note: I Highly recommend you not to COPY and PASTE the answers. Try to understand the concept first and then try to solve the question.

we are going to execute all these commands in jump host itself.

  1. creating a pod

    $ vi httpd-pod.yaml

    Note: yaml file name is our choice, we can name it however we want to be. It doesn't impact the end result.

     apiVersion: v1
     kind: Pod
     metadata:
       name: frontend
     spec:
       containers:
       - name: app
         image: images.my-company.example/app:v4
         resources:
           requests:
             memory: "64Mi"
             cpu: "250m"
           limits:
             memory: "128Mi"
             cpu: "500m"
    

$ kubectl apply -f httpd-pod.yaml

with the help of this command, we are informing our node to create a pod with the specified details.

$ k get pods

To get the list of pods

$ k get describe pod httpd-pod

Use this command to verify our changes.

And that's it. we completed the task.

Reference : Resource Management for Pods and Containers | Kubernetes

KodeKloud Engineer

we will meet in the next article with another interesting topic, till then keep practicing.

please like 👍, follow Nagacharan, share and comment 💬your views on this article.

Did you find this article valuable?

Support Nagacharan by becoming a sponsor. Any amount is appreciated!