I would like to save node name which consuming highest CPU (in the current namespace) into the file.
kubectl top node
provide you all nodes information, need to pick the top one from the list.
Ideal command to get the sorted list is kubectl top node --no-headers --sort-by='cpu' | head -1 > somefilename.txt
, but the result will be inconsistent due to open issue kubectl top issue
As a workaround you can try this command if you are running in any linux/mac OS:
kubectl top node --no-headers | sort -k3 -n | tail -1 > somefilename.txt
This issue has been resolved in kubectl 1.18.