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
  - ````

Signed-off-by: Neeraj Krishna Gopalakrishna <[email protected]>
@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
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.

1 participant