Skip to content

kubectl top pods filter by the node #131896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
taraspos opened this issue May 1, 2025 · 6 comments
Open

kubectl top pods filter by the node #131896

taraspos opened this issue May 1, 2025 · 6 comments
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation.

Comments

@taraspos
Copy link

taraspos commented May 1, 2025

What would you like to be added:

I would like to be able to see resource consumption for all pods running on the specific node only.

kubectl top pods --field-selector spec.nodeName=<name>

Currently this command is failing with:

➜  ~ kubectl top pods --field-selector spec.nodeName=<node> -A
Error from server (BadRequest): "spec.nodeName" is not a known field selector: only "metadata.name", "metadata.namespace"

Why is this needed:

This is useful when investigating node resource pressure. Let's say that I run kubectl top nodes --sort-by='memory' and see that one of my nodes is on 95% memory usage. The next logical thing to do is to find what are the most memory intensive pods.

I can run kubectl describe node <name>, this will give me list of pods and their memory requests and limits but not the usage.

Currently this can be fetched by the following overly-complicated command:

kubectl get pods --field-selector spec.nodeName='<name>' -A -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name --no-headers | \ 
   xargs -I {} sh -c "kubectl top pod --no-headers -n {}" | \
   column -t

Related issues:

@taraspos taraspos added the kind/feature Categorizes issue or PR as related to a new feature. label May 1, 2025
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label May 1, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@googs1025
Copy link
Member

/assign
This seems reasonable, I will look at the feasibility of adding a flag

@mpuckett159
Copy link
Contributor

@ardaguclu is going to reach out. to sig-instrumentation because they are in charge of what data is available in the Metrics API (the API that is communicated with to get the information displayed in kubectl top pods) and if they are willing to add this field to the pod metrics data we can move forward with this.

If not, we will close this issue and you can watch kubernetes/kubectl#1706 to be closed and that will simplify your bash command by allowing you to grep the output easily.

@ardaguclu
Copy link
Member

/transfer kubernetes

@k8s-ci-robot k8s-ci-robot transferred this issue from kubernetes/kubectl May 22, 2025
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label May 22, 2025
@ardaguclu
Copy link
Member

/sig instrumentation
/sig cli

@k8s-ci-robot k8s-ci-robot added sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 22, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG CLI May 22, 2025
@ardaguclu
Copy link
Member

@kubernetes/sig-instrumentation-leads we need your input in here. There is an attempt #130525 that manually fetches the node of the pod name and links the node name to the output of retrieved from metrics API. Is this correct?. Is there any similar discussions about adding a node name field in metrics API for "top pods"?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation.
Projects
Status: Needs Triage
Development

No branches or pull requests

5 participants