Kubernetes top vs Linux top [英] Kubernetes top vs Linux top

查看:15
本文介绍了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

以下命令有如下输出:

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.

问题是这与显示仅使用 1205 mb 的kubectl top"相矛盾.

Issue is this contradicts "kubectl top" which shows only 1205 mb used.

推荐答案

Command 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/meminfofile to get an actual information about current memory status. Containers inside pods partially share /procwith 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 top vs Linux top的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆