Set Limits for Resources in Kubernetes

Ticker

6/recent/ticker-posts

Set Limits for Resources in Kubernetes

Question : Recently some of the performance issues were observed with some applications hosted on Kubernetes cluster. The Nautilus DevOps team has observed some resources 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 resources utilization. Below you can find more details.

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

Requests: Memory: 15Mi, CPU: 1

Limits: Memory: 20Mi, CPU: 2

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


Please Note :-  Perform the below commands based on your question  server,  user name & other details might differ . So please read task carefully before executing. All the Best 👍

Solution:  

1. At first  kubectl  utility configure and working from jump server, run below                commands

    kubectl get namespace

    kubectl get pods


2.  Create yaml  file with all the parameters , you can copy form gitlab

    https://gitlab.com/nb-tech-support/devops.git

    Refer Below Video for more clarity )

apiVersion: v1

kind: Pod

metadata:

  name: httpd-pod

spec:

  containers:

  - name: httpd-container

    image: httpd:latest

    resources:

      requests:

        memory: "15Mi"

        cpu: "1"

      limits:

        memory: "20Mi"

        cpu: "2"

 


3.  Run below command to create pod
    

thor@jump_host /$ kubectl create -f /tmp/limit.yaml

pod/httpd-pod created

thor@jump_host /$



4.  Wait for  pods to get running status    

thor@jump_host /$ kubectl get pods

NAME        READY   STATUS    RESTARTS   AGE

httpd-pod   1/1     Running   0          9s

thor@jump_host /$


5.  Validate the task by running     

thor@jump_host /$ kubectl describe pods httpd-pod

Name:         httpd-pod

Namespace:    default

Priority:     0

Node:         node01/172.17.0.25

Start Time:   Mon, 07 Jun 2021 14:49:28 +0000

Labels:       <none>

Annotations:  <none>

Status:       Running

IP:           10.244.2.2

IPs:

  IP:  10.244.2.2

Containers:

  httpd-container:

    Container ID:   docker://111c5345a3140c069c9e8d17c7da90c22f7683c576cced2d96729a6d00d2c9cd

    Image:          httpd:latest

    Image ID:       docker-pullable://httpd@sha256:48bae0ac5d0d75168f1c1282c0eb21b43302cb1b5c5dc9fa3b4a758ccfb36fe9

    Port:           <none>

    Host Port:      <none>

    State:          Running

      Started:      Mon, 07 Jun 2021 14:49:34 +0000

    Ready:          True

    Restart Count:  0

    Limits:

      cpu:     2

      memory:  20Mi

    Requests:

      cpu:        1

      memory:     15Mi

    Environment:  <none>

    Mounts:

      /var/run/secrets/kubernetes.io/serviceaccount from default-token-xh465 (ro)

Conditions:

  Type              Status

  Initialized       True

  Ready             True

  ContainersReady   True

  PodScheduled      True

Volumes:

  default-token-xh465:

    Type:        Secret (a volume populated by a Secret)

    SecretName:  default-token-xh465

    Optional:    false

QoS Class:       Burstable

Node-Selectors:  <none>

Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s

                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s

Events:

  Type    Reason     Age   From               Message

  ----    ------     ----  ----               -------

  Normal  Scheduled  51s   default-scheduler  Successfully assigned default/httpd-pod to node01

  Normal  Pulling    49s   kubelet            Pulling image "httpd:latest"

  Normal  Pulled     44s   kubelet            Successfully pulled image "httpd:latest" in 5.025161084s

  Normal  Created    44s   kubelet            Created container httpd-container

  Normal  Started    44s   kubelet            Started container httpd-container

thor@jump_host /$

 


6.  Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge




Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user