From the pod lable name=pod, find pods running high CPU workloads and write the .

Venkat:
From the pod lable name=pod, find pods running high CPU workloads and write the name of the pod consuming most to the file. how to solve this?

Hải Đông:
i do it manually
k top po | grep label. Check the most consuming pod and write in the file. not sure its correct

1 Like

Marco Tony:
I guess:

  1. kubectl top pods
  2. parsing the output through the jsonpath or jq creating a kind of csv like: consumption,pod_name
  3. sort the output through the sort utility
  4. get last line through the tail -1

samith perera:
kubectl top pods -l name=pod

Venkat:
@Tej_Singh_Rana is it right?

sharan:
@Venkat kubectl top pod --sort-by cpu name=pod

Kubs:
kubectl top pod --sort-by cpu -l name=pod

Hải Đông:
@sharan and write manually in the specified file ?

k top pods -A --sort-by cpu --no-headers | head -1 > file.txt

kubectl top pod -A --selector=name=pod --all-namespaces

1 Like

k top nodes --sort-by cpu --no-headers | head -1 | awk ‘{print $1 }’ > output.txt