题目主干
Task
通过 pod label name=cpu-loader,找到运行时占用大量 CPU 的 pod,
并将占用 CPU 最高的 pod 名称写入文件 /opt/KUTR000401/KUTR00401.txt(已存在)。
参考说明
通过帮助命令查看相关参数
student@master01:~$ kubectl top pod -hDisplay resource (CPU/memory) usage of pods.The 'top pod' command allows you to see the resource consumption of pods.Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation.Aliases:pod, pods, poExamples:# Show metrics for all pods in the default namespacekubectl top pod# Show metrics for all pods in the given namespacekubectl top pod --namespace=NAMESPACE# Show metrics for a given pod and its containerskubectl top pod POD_NAME --containers# Show metrics for the pods defined by label name=myLabelkubectl top pod -l name=myLabelOptions:-A, --all-namespaces=false: If present, list the requested object(s) across all namespaces. Namespace in currentcontext is ignored even if specified with --namespace.--containers=false: If present, print usage of containers within a pod.--field-selector='': Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selectorkey1=value1,key2=value2). The server only supports a limited number of field queries per type.--no-headers=false: If present, print output without headers.-l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)--sort-by='': If non-empty, sort pods list using specified field. The field can be either 'cpu' or 'memory'.--use-protocol-buffers=true: Enables using protocol-buffers to access Metrics API.Usage:kubectl top pod [NAME | -l label] [options]Use "kubectl options" for a list of global command-line options (applies to all commands).student@master01:~$
题目解答
student@master01:~$ kubectl top pod -l name=cpu-loader --sort-by=cpu -ANAMESPACE NAME CPU(cores) MEMORY(bytes)cpu-top redis-test 2m 3Micpu-top nginx-host 0m 4Micpu-top test0 0m 8Mistudent@master01:~$ sudo mkdir -p /opt/KUTR000401/student@master01:~$ sudo touch /opt/KUTR000401/KUTR00401.txtstudent@master01:~$ sudo echo "redis-test" > /opt/KUTR000401/KUTR00401.txtstudent@master01:~$ cat /opt/KUTR000401/KUTR00401.txt
