题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
Find the Node that consumes the most MEMORY in all cluster(currently we have single cluster). Then, store the result in the file high_memory_node.txt with the following format: cluster_name,node_name .
找出所有集群中消耗内存最多的节点(目前我们只有一个集群)。然后,将结果以下格式存储在high_memory_node.txt
文件中:cluster_name,node_name
。
解题思路
- 切换K8S集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 查找集群中节点内存使用最多的节点,并把结果存在变量node中
node=$(kubectl top nodes --sort-by=memory --no-headers | head -n 1 | awk '{print $1}')
- 查找集群名称
cluster_name=$(kubectl config view --minify -o=jsonpath='{.clusters[0].name}')
- 并按照题目的要求把结果输出到指定文件中
echo "$cluster_name,$node" > high_memory_node.txt