I have a doubt for below type of questions:
Find the node across all clusters that consumes the most CPU and store the result to the file /opt/high_cpu_node
in the following format cluster_name,node_name
.
The node could be in any clusters that are currently configured on the student-node
.
NOTE: It’s recommended to wait for a few minutes to allow deployed objects to become fully operational and start consuming resources.
===========================================================================
Solution provided by Kodecloud:
student-node ~ ➜ kubectl top node --context cluster1 --no-headers | sort -nr -k2 | head -1
cluster1-controlplane 127m 1% 703Mi 1%
student-node ~ ➜ kubectl top node --context cluster2 --no-headers | sort -nr -k2 | head -1
cluster2-controlplane 126m 1% 675Mi 1%
student-node ~ ➜ kubectl top node --context cluster3 --no-headers | sort -nr -k2 | head -1
cluster3-controlplane 577m 7% 1081Mi 1%
student-node ~ ➜ kubectl top node --context cluster4 --no-headers | sort -nr -k2 | head -1
cluster4-controlplane 130m 1% 679Mi 1%
student-node ~ ➜
student-node ~ ➜
student-node ~ ➜ echo cluster3,cluster3-controlplane > /opt/high_cpu_node
Solution provided by me:
student-node ~ ➜ cat /opt/high_cpu_node
cluster1,cluster1-controlplane
student-node ~ ➜ kubectl top node --context cluster1 --no-headers | sort -nr -k2 | head -1
cluster1-controlplane 499m 1% 1075Mi 0%
student-node ~ ➜ kubectl top node --context cluster2 --no-headers | sort -nr -k2 | head -1
cluster2-controlplane 111m 0% 862Mi 0%
student-node ~ ➜ kubectl top node --context cluster3 --no-headers | sort -nr -k2 | head -1
cluster3-controlplane 109m 0% 1461Mi 0%
student-node ~ ➜ kubectl top node --context cluster4 --no-headers | sort -nr -k2 | head -1
cluster4-controlplane 120m 0% 943Mi 0%
=====================================================================
You should fix this in backend. Everytime i face this issue.