Skip to content

Conversation

@ngopalak-redhat
Copy link
Contributor

@ngopalak-redhat ngopalak-redhat commented Oct 29, 2025

Problem

On very large clusters, getting node resource usage currently requires one of these approaches:

  1. kubectl top nodes (Without MCP) - Returns metrics for all nodes in the cluster, requiring manual filtering to find the specific node of interest
  2. Manual calculation - Fetch NodeMetrics resource and Node resource separately, then calculate usage percentages manually

Both methods are inefficient for large clusters as there is additional processing overhead to calculate percentages from raw metrics. Also additional token usage.

Solution

This PR implements a nodes_top tool that provides a streamlined interface similar to kubectl top nodes, following the pattern established by the pods_top tool added earlier this year (#119).

Example usage:
nodes_top(name="ip-10-0-10-197.ec2.internal")

Testing:

> using kubernetes-local-mcp-server find the node usage

⏺ I'll retrieve the resource usage for all nodes in the cluster.
  ⎿  NAME                          CPU(cores)   CPU(%)   MEMORY(bytes)   MEMORY(%)   SWAP(bytes)   SWAP(%)
     ip-10-0-10-197.ec2.internal   546m         15%      5219Mi          35%         0Mi
     ip-10-0-151-28.ec2.internal   364m         10%      3854Mi          26%         0Mi
     … +4 lines (ctrl+o to expand)

⏺ Here's the resource usage across all nodes in the cluster:

  | Node                        | CPU (cores) | CPU (%) | Memory | Memory (%) | Swap |
  |-----------------------------|-------------|---------|--------|------------|------|
  | ip-10-0-10-197.ec2.internal | 546m        | 15%     | 5219Mi | 35%        | 0Mi  |
  | ip-10-0-151-28.ec2.internal | 364m        | 10%     | 3854Mi | 26%        | 0Mi  |
  | ip-10-0-20-71.ec2.internal  | 234m        | 6%      | 3726Mi | 25%        | 0Mi  |
  | ip-10-0-32-244.ec2.internal | 101m        | 2%      | 1639Mi | 11%        | 0Mi  |
  | ip-10-0-34-240.ec2.internal | 396m        | 11%     | 7463Mi | 51%        | 0Mi  |
  | ip-10-0-83-138.ec2.internal | 557m        | 15%     | 9496Mi | 65%        | 0Mi  |

  Key observations:
  - Highest CPU usage: ip-10-0-83-138 (15%, 557m cores)
  - Highest memory usage: ip-10-0-83-138 (65%, 9496Mi)
  - Lowest resource usage: ip-10-0-32-244 (2% CPU, 11% memory)
  - No swap is being used on any node
  - ````

@ngopalak-redhat ngopalak-redhat marked this pull request as ready for review October 29, 2025 11:37
@manusa manusa self-requested a review October 29, 2025 14:07
@manusa manusa changed the title Support for nodes_top similar to pods_top feat(nodes): nodes_top retrieves Node resource consumption(metrics API) Nov 3, 2025
@manusa manusa added this to the 0.1.0 milestone Nov 3, 2025
Signed-off-by: Neeraj Krishna Gopalakrishna <[email protected]>
@manusa manusa changed the title feat(nodes): nodes_top retrieves Node resource consumption(metrics API) feat(nodes): nodes_top retrieves Node resource consumption (metrics API) Nov 4, 2025
@manusa manusa force-pushed the ngopalak/kubectl_top branch from f8170f4 to d1a2916 Compare November 4, 2025 09:25
Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx!

@manusa manusa merged commit 1783144 into containers:main Nov 4, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants