我正在做CKA,偶然发现了一个我搞不懂的问题。我不记得所有的细节,但它是这样的:
根据CPU的消耗量获取前1节点/节目单,并将其放在{path}的文件中。
kubectl top nodes/pod --sort-by cpu <-- this orders by ascending. So you have to hardcode the last node/pod.发布于 2021-01-11 11:12:47
如果需要提取顶部吊舱的名称并将其保存在文件中,则可以这样做:
,让我们假设你有3个吊舱:
$ kubectl top pod --sort-by cpu
NAME CPU(cores) MEMORY(bytes)
nats-depl-6c4b4dfb7c-tjpgv 2m 4Mi
project-depl-595bbd56db-lb6vb 8m 180Mi
auth-depl-64cccc484f-dn7w5 4m 203Mi你可以这样做:
$ kubectl top pod --sort-by cpu | head -2 | tail -1 | awk {'print $1'}
chat-depl-6dd798699b-l7wcl #### < == returns name of the pod
## you can redirect it to any file
$ kubectl top pod --sort-by cpu | head -2 | tail -1 | awk {'print $1'} > ./file_name
$ cat ./file_name
chat-depl-6dd798699b-l7wcl #### < == returns name of the podhttps://stackoverflow.com/questions/65665732
复制相似问题