Getting Practical with Container Memory and CPU Resources

Explore the usage of resources with the help of some practical examples.

In the previous lesson, we discussed the theory of resources. Let’s get practical by looking into some practical examples related to resources.

Creating the resources#

We’ll move on and create the resources defined in the go-demo-2-random.yml file.

Create pod 'go-demo-2-random'

We created the resources and waited until the go-demo-2-api Deployment was rolled out. The output of the later command should be as follows.

Output of above command

Let’s describe the go-demo-2-api Deployment and see its limits and requests.

Describe the `go-demo-2-api` deployment

The output, limited to the limits and the requests, is as follows.

Output of the above command

We can see that the limits and the requests correspond to those we defined in the go-demo-2-random.yml file. That should come as no surprise.

Looking into the nodes’ description#

Let’s describe the nodes that form the cluster (even though there’s only one).

Describe nodes

The output, limited to the resource-related entries, is as follows.

Output of above command

Line 2-7: The Capacity represents the overall capacity of a node. In our case, the mycluster node has 2 CPUs, 6GB of RAM, and can run up to one hundred and ten Pods. Those are the upper limits imposed by the hardware.

Line 10-20: Further down is the Non-terminated Pods section. It lists all the Pods with the CPU and memory limits and requests. We can, for example, see that the go-demo-2-db Pod has the memory limit set to 300Mi, which is 15% of the capacity. Similarly, we can see that not all Pods have specified resources. For example, the metrics-server Pod has all the values set to 0. Kubernetes will not be able to handle those Pods appropriately.

Line 23-28: The Allocated resources section provides summed values from all the Pods. We can, for example, see that the CPU limits are 55%. Limits can be even higher than 100%, and that would not necessarily be a thing to worry about. Not all the containers will have memory and CPU bursts over the requested values. Even if that happens, Kubernetes will know what to do.

What truly matters is that the total amount of requested memory and CPU is within the limits of the capacity. That, however, leads us to an interesting question. What is the basis for the resources we defined so far?

Try it yourself#

A list of all the commands used in the lesson is given below.

Commands used in this lesson

You can practice the commands in the following code playground by pressing the Run button and waiting for the cluster to set up.

/
go-demo-2-random.yml
Exploring container memory and CPU resources
Defining Container Memory and CPU Resources
Measuring the Actual Memory and CPU Consumption
Mark as Completed
Report an Issue