Task - From the pod label name=overloaded-cpu, find pods running high CPU workloads and write the name of the pod consuming most CPU to the file /opt/ KUTR00401/KUTR00401.txt (which already exists).
Why would they add "(which already exists)"? It just confuses matters. In other questions they do not add this qualification. Makes me wonder if that file is empty?
Maybe first
# cat /opt/KUTR00401/KUTR00401.txt
to make sure it's empty.
If it's not,
# echo "name-of-top-cpu-pod" >> /opt/KUTR00401/KUTR00401.txt
Instead of
# echo "name-of-top-cpu-pod" > /opt/KUTR00401/KUTR00401.txt
Or am I overthinking here?
kubectl top pod -l name=overloaded-cpu --sort-by=cpu | head -n 1 > /opt/KUTR00401/KUTR00401.txt
## Note: The --sort-by=cpu flag will sort the pods by CPU usage, but to capture only the topmost CPU-consuming pod (not all pods), you'll need to use head -n 1 to select the first result.
## | head -n 1: Selects the pod with the highest CPU usage from the sorted list.
Frankly speaking, why bother typing the pod name with this single liner:
# Dry-run
k top po -l name=overloaded-cpu --sort-by=cpu -A --no-headers | head -n 1 | awk '{print $2}'
# Exec
k top po -l name=overloaded-cpu --sort-by=cpu -A --no-headers | head -n 1 | awk '{print $2}' >> /opt/KUTR00401/KURT00401.txt
I think the answer should be: overloaded-cpu-98b9se
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Bensaid
Highly Voted 1 year, 6 months agodirkdirkdirk
Highly Voted 1 year, 9 months agomchahed
1 year, 9 months agoNasser_Sam
Most Recent 4 weeks, 1 day agonoahsark
1 month, 1 week agoArchanakaviya
2 months ago[Removed]
4 months, 2 weeks agozanhsieh
7 months, 2 weeks agodonid323
1 year, 5 months agoChinensis
1 year, 10 months ago