See cluster resources usage with kubectl command

Print Friendly, PDF & Email

Monitoring resources is among the significantly important tasks of an engineer working with Kubernetes. In the K8s ecosystem, we can find a range of tools and software allow us to check resources, monitor the amount of memory and CPU being used, etc. In this post, I am sharing with you what I have stumbled upon tips and tricks suggested in a discussion on K8s issues.

Looking for manners to see how much memory and CPU have been used and remain in my K8s cluster, I have caught a discussion on this topic.

List of commands

Here are the suggested tips and utilities we can use to check our K8s resources.

kubectl top nodes

$ kubectl top nodes
NAME                    CPU(cores)   CPU%      MEMORY(bytes)   MEMORY%   
cluster1-k8s-master-1   312m         15%       1362Mi          68%       
cluster1-k8s-node-1     124m         12%       233Mi           11%

kubectl describe node

A guy shared a hack

kubectl describe nodes | grep -A 2 -e "^\\s*CPU Requests"

Even better to write tips into a script like below

$ cat bin/node-resources.sh 
#!/bin/bash
set -euo pipefail

echo -e "Iterating...\n"

nodes=$(kubectl get node --no-headers -o custom-columns=NAME:.metadata.name)

for node in $nodes; do
  echo "Node: $node"
  kubectl describe node "$node" | sed '1,/Non-terminated Pods/d'
  echo
done

You can take a look at the discussion from the link I attached above to see other solutions to comply with your need.

That’s it!

Summary

Above are the commands which are useful to monitor K8s resources so as to determine which nodes should be shut down to save memory for other tasks. I hope you find this post interesting.

Please consider to encourage us by following the instructions below.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code

This site uses Akismet to reduce spam. Learn how your comment data is processed.