题目

 Task

From the pod label name=cpu-user,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).

答案

kubectl top [flags] [options]显示资源(CPU/内存/存储)的使用情况。
#查看cpu使用率
$ kubectl config use-context k8s
$ kubectl top pod -l name=cpu-user -A
NAMAESPACE   NAME         CPU   MEM
delault      cpu-user-1   45m   6Mi
delault      cpu-user-2   38m   6Mi
delault      cpu-user-3   35m   7Mi
delault      cpu-user-4   32m   10Mi
$ echo 'cpu-user-1' >>/opt/KUTR00401/KUTR00401.txt

#或者使用筛选
$ for i in `kubectl top pod -l name=cpu-user -A |awk '{if (NR > 1){print $1}}'|sort |uniq `;do echo $i >>/opt/KUTR00401/KUTR00401.txt;done

对kubectl的命令了解:https://kubernetes.io/zh/docs/reference/kubectl/overview/

为容器和 Pods 分配 CPU 资源 :https://kubernetes.io/zh/docs/tasks/configure-pod-container/assign-cpu-resource/

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐