Friday, March 25, 2022

Resource Quota - K8

  Resource Quota:

Object Base:

Number of pods per namespace

Compute  Base:

cpu 

memory


root@ip-172-31-3-126:~# kubectl create ns devns

namespace/devns created

root@ip-172-31-3-126:~# kubectl describe ns devns

Name:         devns

Labels:       kubernetes.io/metadata.name=devns

Annotations:  <none>

Status:       Active


No resource quota.


No LimitRange resource.

root@ip-172-31-3-126:~#


root@ip-172-31-3-126:~# kubectl explain resourcequota

KIND:     ResourceQuota

VERSION:  v1


DESCRIPTION:

     ResourceQuota sets aggregate quota restrictions enforced per namespace


FIELDS:

   apiVersion   <string>

     APIVersion defines the versioned schema of this representation of an

     object. Servers should convert recognized schemas to the latest internal

     value, and may reject unrecognized values. More info:

     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources


   kind <string>

     Kind is a string value representing the REST resource this object

     represents. Servers may infer this from the endpoint the client submits

     requests to. Cannot be updated. In CamelCase. More info:

     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds


   metadata     <Object>

     Standard object's metadata. More info:

     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata


   spec <Object>

     Spec defines the desired quota.

     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status


   status       <Object>

     Status defines the actual enforced quota and its current usage.

     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status





===============


root@ip-172-31-3-126:~# cat myquota.yml

apiVersion: v1

kind: ResourceQuota

metadata:

   name: myquota

spec:

   hard:

     pods: 2



===========



root@ip-172-31-3-126:~#

root@ip-172-31-3-126:~# kubectl apply -f myquota.yml -n devns

resourcequota/myquota created

root@ip-172-31-3-126:~# kubectl describe ns devns

Name:         devns

Labels:       kubernetes.io/metadata.name=devns

Annotations:  <none>

Status:       Active


Resource Quotas

  Name:     myquota

  Resource  Used  Hard

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

  pods      0     2


No LimitRange resource.

root@ip-172-31-3-126:~#



================


pod yml:


apiVersion: v1

kind: Pod

metadata:

     name: mypod1

     labels:

         type: devpod

spec:

   containers:

           - name: my-container

             image: nginx

          

=========================


Create two Pods


root@ip-172-31-3-126:~# kubectl get pods -n devns

NAME     READY   STATUS    RESTARTS   AGE

mypod1   1/1     Running   0          3m8s

mypod2   1/1     Running   0          2m33s

root@ip-172-31-3-126:~#




root@ip-172-31-3-126:~# kubectl describe ns devns

Name:         devns

Labels:       kubernetes.io/metadata.name=devns

Annotations:  <none>

Status:       Active


Resource Quotas

  Name:     myquota

  Resource  Used  Hard

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

  pods      2     2


No LimitRange resource.

root@ip-172-31-3-126:~#


Now our  resource quota is fulll..


On trying to create new pod we will get below error.


root@ip-172-31-3-126:~# kubectl run webserver --image=nginx -n devns

Error from server (Forbidden): pods "webserver" is forbidden: exceeded quota: myquota, requested: pods=1, used: pods=2, limited: pods=2

root@ip-172-31-3-126:~#



Compute Base Quota:


creta yml with below details:


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

apiVersion: v1

kind: ResourceQuota

metadata:

   name: myquota

spec:

   hard:

       requests.cpu: 0.5

       requests.memory: 500Mi

       limits.cpu: 1

       limits.memory: 1Gi

=-------------


root@ip-172-31-3-126:~# kubectl apply -f myquota.yml -n testns

resourcequota/myrsourcequota created

root@ip-172-31-3-126:~# kubectl describe ns testns

Name:         testns

Labels:       kubernetes.io/metadata.name=testns

Annotations:  <none>

Status:       Active


Resource Quotas

  Name:            myrsourcequota

  Resource         Used  Hard

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

  limits.cpu       0     1

  limits.memory    0     1Gi

  requests.cpu     0     500m

  requests.memory  0     500Mi


No LimitRange resource.

root@ip-172-31-3-126:~#


root@ip-172-31-3-126:~# kubectl get resourcequota -n testns

NAME             AGE     REQUEST                                          LIMIT

myrsourcequota   2m36s   requests.cpu: 0/500m, requests.memory: 0/500Mi   limits.cpu: 0/1, limits.memory: 0/1Gi

root@ip-172-31-3-126:~#




root@ip-172-31-3-126:~# kubectl run webserver --image=nginx -n testns

Error from server (Forbidden): pods "webserver" is forbidden: failed quota: myrsourcequota: must specify limits.cpu,limits.memory,requests.cpu,requests.memory

root@ip-172-31-3-126:~#


We cant run pod without resource details..



Create beow yml file with resource details:


apiVersion: v1

kind: Pod

metadata:

     name: mypod1

     labels:

         type: devpod

spec:

   containers:

           - name: my-container

             image: nginx

             resources:

                   requests:

                       memory: 250Mi

                       cpu: 0.1

                   limits:

                       cpu: 0.5

                       memory: 500Mi



===

root@ip-172-31-3-126:~# kubectl apply -f mypod.yml -n testns

pod/mypod1 created

root@ip-172-31-3-126:~# kubectl describe ns testns

Name:         testns

Labels:       kubernetes.io/metadata.name=testns

Annotations:  <none>

Status:       Active


Resource Quotas

  Name:            myrsourcequota

  Resource         Used   Hard

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

  limits.cpu       500m   1

  limits.memory    500Mi  1Gi

  requests.cpu     100m   500m

  requests.memory  250Mi  500Mi


No LimitRange resource.



root@ip-172-31-3-126:~# kubectl apply -f mypod.yml -n testns

pod/mypod2 created

root@ip-172-31-3-126:~# kubectl describe ns testns

Name:         testns

Labels:       kubernetes.io/metadata.name=testns

Annotations:  <none>

Status:       Active


Resource Quotas

  Name:            myrsourcequota

  Resource         Used    Hard

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

  limits.cpu       1       1

  limits.memory    1000Mi  1Gi

  requests.cpu     200m    500m

  requests.memory  500Mi   500Mi


No LimitRange resource.

root@ip-172-31-3-126:~#


Now our resource limit reached to hard limit..


We cant create pod


root@ip-172-31-3-126:~# kubectl apply -f mypod.yml -n testns

Error from server (Forbidden): error when creating "mypod.yml": pods "mypod3" is forbidden: exceeded quota: myrsourcequota, requested: limits.cpu=500m,limits.memory=500Mi,requests.memory=250Mi, used: limits.cpu=1,limits.memory=1000Mi,requests.memory=500Mi, limited: limits.cpu=1,limits.memory=1Gi,requests.memory=500Mi

root@ip-172-31-3-126:~#


=======













No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117