题干
For this question, please set this context (In exam, diff cluster name)
对于此问题,请设置此上下文(在考试中,diff 集群名称)
kubectl config use-context kubernetes-admin@kubernetes
Find the pod that consumes the most CPU in all namespace(including kube-system) in all cluster(currently we have single cluster). Then, store the result in the file high_cpu_pod.txt with the following format: pod_name,namespace .
在所有集群(当前我们只有一个集群)中,在所有命名空间(包括kube-system)中,找到消耗CPU最多的pod,然后将结果以如下格式存储到文件high_cpu_pod.txt中:pod_name,namespace。
解题思路
- 切换K8S集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 通过kubectl top命令根据CPU排序查询
top pod -A --sort-by=cpu | awk -F ' ' '{print $2,$1}' | head -n 2 > high_cpu_pod.txt