The CPU resources we are going to see here are

- CPU request = Minimum or guaranteed CPU for the container

- CPU limit = Maximum CPU, should not exceed for the container

 

Let’s define the Pod configuration

networkandcode@cloudshell:~ (kubernetes-cka-224606)$ cat ex4.yml

---

apiVersion: v1

kind: Pod

metadata:

 name: pod4

 namespace: default

spec:

 containers:

 - name: ctr4

   image: vish/stress

   resources:

     requests:

       cpu: "0.5"

     limits:

       cpu: "1"

   args: ["-cpus", "2"]  #attempt to use 2 CPUs

...

 

Let’s create the Pod and check the metrics

networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl create -f ex4.yml

pod/pod4 created

networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get pod pod4

NAME   READY STATUS    RESTARTS AGE

pod4   1/1 Running   0 8s

 

networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl top pods pod4

NAME   CPU(cores)   MEMORY(bytes)

pod4   962m      0Mi

 

So, it’s currently consuming 962 milli CPU, which is slightly less than the specified limit(1 CPU).

 

Let’s define another Pod with very high CPU request, which none of the node in the cluster can accommodate

etworkandcode@cloudshell:~ (kubernetes-cka-224606)$ cat ex5.yml

---

apiVersion: v1

kind: Pod

metadata:

 name: pod5

 namespace: default

spec:

 containers:

 - name: ctr5

   image: vish/stress

   resources:

     requests:

       cpu: "40"

     limits:

       cpu: "50"

   args: ["-cpus", "2"]  #attempt to use 2 CPUs

...

 

The Pod should remain Pending state
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get pods pod5

NAME   READY STATUS    RESTARTS AGE

pod5   0/1 Pending   0 23s

 

Reference:

https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/

 

--end-of-post--