Kubernetes置顶vs Linux置顶 [英] Kubernetes top vs Linux top
问题描述
Kubernetes top(kubectl top)命令显示的内存使用情况与在pod内部运行的Linux top命令不同.
Kubernetes top (kubectl top) command shows different memory usage than Linux top command ran inside pod.
我创建了k8s部署,其中YAML包含以下内存限制:
I’ve created k8s deployment where YAML contains these memory limits:
resources:
limits:
cpu: "1"
memory: 2500Mi
requests:
cpu: 200m
memory: 2Gi
以下命令的输出如下所示:
Following commands have output as shown:
bash4.4$ kubectl top pod PODNAME
NAME CPU(cores) MEMORY(bytes)
openam-d975d46ff-rnp6h 2m 1205Mi
运行linux top命令:
Run linux top command:
Kubectl exec -it PODNAME top
Mem: 12507456K used, 4377612K free, 157524K shrd,
187812K buff, 3487744K cached
请注意,"free -g"也会显示已使用11Gb.
Note ‘free -g’ also shows 11Gb used.
问题是这与"kubectl top"矛盾,后者仅显示使用的1205 mb.
Issue is this contradicts "kubectl top" which shows only 1205 mb used.
推荐答案
命令kubectl top
显示给定Pod的度量.该信息基于 cAdvisor 的报告,该报告收集了实际Pod资源的使用情况.
Command kubectl top
shows metrics for a given pod. That information is based on reports from cAdvisor, which collects real pods resource usage.
如果在Pod内运行top
,则就像在主机系统上运行一样,因为Pod使用的是主机系统的内核.
Unix top
使用proc
虚拟文件系统并读取/proc/meminfo
文件以获取有关当前内存状态的实际信息. Pod中的容器与主机系统部分共享/proc
,其中包含有关内存和CPU信息的路径.
If you run top
inside the pod, it will be like you run it on the host system because the pod is using kernel of the host system.
Unix top
uses proc
virtual filesystem and reads /proc/meminfo
file to get an actual information about current memory status. Containers inside pods partially share /proc
with the host system include path about a memory and CPU information.
您可以在以下文档中找到更多信息: kubectl-top-pod手册页, Linux容器内的内存
More information you can find in these documents: kubectl-top-pod man page, Memory inside Linux containers
这篇关于Kubernetes置顶vs Linux置顶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!