Skip to content

kubectl top pods filter by the node #131896

Open
@taraspos

Description

@taraspos

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:

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.sig/cliCategorizes an issue or PR as relevant to SIG CLI.sig/instrumentationCategorizes an issue or PR as relevant to SIG Instrumentation.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

Status

Needs Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions