k9s icon indicating copy to clipboard operation
k9s copied to clipboard

feat: add node-alloc view

Open v0y4g3r opened this issue 2 months ago • 4 comments

Related issues:

  • close #3529
  • also related to #2723

Main changes

This PR introduces a new nodes-alloc view that provides detailed resource allocation information for Kubernetes nodes, including CPU and memory requests from all pods scheduled on each node. The view is optimized for capacity planning and resource utilization analysis.

Motivation

The standard nodes view shows node capacity and current usage, but doesn't display the total requested resources from pods. This makes it difficult to:

  • Understand how much of a node's capacity is actually requested by workloads
  • Identify nodes that are over-committed or under-utilized
  • Plan capacity based on resource requests rather than just current usage

The new nodes-alloc view addresses this by always calculating and displaying requested CPU and memory resources, providing a clearer picture of resource allocation across the cluster.

Changes

New Features

  1. New nodes-alloc view (:na or :nodes-alloc)

    • Dedicated view for resource allocation analysis
    • Always calculates requested CPU and memory from pods
    • Shows both absolute values and percentages
    • Streamlined column layout focused on resource metrics
  2. Resource Request Calculation

    • Calculates sum of CPU and memory requests from all non-terminated pods
    • Properly handles init containers (uses maximum init container resources)
    • Skips terminated pods (Succeeded/Failed states)
    • Falls back to limits when requests are not specified
  3. Performance Optimization

    • Requested resource calculation is deferred to the nodes-alloc view only
    • Regular nodes view no longer performs expensive pod resource calculations
    • Improves performance of the standard nodes view when pod counting is disabled

v0y4g3r avatar Nov 19 '25 08:11 v0y4g3r

@v0y4g3r Thank you for this update! Tho I do see the value in computing these columns, I don't think we should volunteer this info in node view as this is an expensive computation and would render k9s worthless depending on node/pod cardinality at the cluster level.

Perhaps an alternate way to handle this, would be to offer and child view that would compute resource usage details per node, so cluster admins can use this to provision their cluster accordingly. Given this would be a separate command, we would not penalize everyone landing in node view and looking for other specific information especially on larger clusters.

What do you think?

derailed avatar Nov 24 '25 13:11 derailed

Perhaps an alternate way to handle this, would be to offer and child view that would compute resource usage details per node

I agree. Could you provide more context so I can proceed? For example, do we need to add a dedicated command (:node_resource), or by "child view" do you mean we can navigate to that list from an existing view? Is there any prior work I could use as a reference?

v0y4g3r avatar Nov 24 '25 21:11 v0y4g3r

@v0y4g3r Thank you Lei!

Sure. Here are my thoughts. I think we could go either way by either introducing a new k9s node view aka node-resources or node-allocs as you've suggested or add an a key action on node view and show allocations details for a selected node. I do think as an admin having a sortable view of node allocs would be awesome so one can figure out cluster provisioning margins/limits. Ultimately we could support both. But we can start with a global node-allocs command which I think would be a good start.

Code wise we have examples of either approaches i.e pod->container views or general views like workloads, dirs, etc.. with a custom dao.

derailed avatar Nov 25 '25 03:11 derailed

@derailed Happy Thanksgiving! I made some changes to this PR in this holiday as we discussed above, please take another look

v0y4g3r avatar Dec 01 '25 07:12 v0y4g3r