kubectl top no内存使用率的计算
1.从下图可以看出node:10.81.163.21的内存使用率93%,该节点总共有7821M(Capacity Memory)物理内存,然后k8s的可分配内存(Allocatable Memory)为5399696Ki
那这个98%是怎么来的?
[root @iZcwfshg0bs9fxZ system]# free -m total used free shared buff/cache available Mem: 7821 5176 1930 1 714 2294 Swap: 0 0 0 [root @iZcwfshg0bs9fxZ system]# kubectl top no NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% 10.81 . 163.21 478m 15 % 5208Mi 98 % [root @iZcwfshg0bs9fxZ system]# kubectl describe no 10.81 . 163.21 Name: 10.81 . 163.21 Roles: <none> Labels: beta.kubernetes.io/arch=amd64 beta.kubernetes.io/os=linux ctet-sc=node kubernetes.io/hostname= 10.81 . 163.21 Annotations: node.alpha.kubernetes.io/ttl: 0 volumes.kubernetes.io/controller-managed-attach-detach: true CreationTimestamp: Wed, 27 Mar 2019 10 : 25 : 48 + 0800 Taints: <none> Unschedulable: false Conditions: Type Status LastHeartbeatTime LastTransitionTime Reason Message ---- ------ ----------------- ------------------ ------ ------- MemoryPressure False Thu, 25 Apr 2019 18 : 59 : 45 + 0800 Tue, 23 Apr 2019 20 : 49 : 53 + 0800 KubeletHasSufficientMemory kubelet has sufficient memory available DiskPressure False Thu, 25 Apr 2019 18 : 59 : 45 + 0800 Wed, 27 Mar 2019 10 : 25 : 52 + 0800 KubeletHasNoDiskPressure kubelet has no disk pressure PIDPressure False Thu, 25 Apr 2019 18 : 59 : 45 + 0800 Wed, 27 Mar 2019 10 : 25 : 52 + 0800 KubeletHasSufficientPID kubelet has sufficient PID available Ready True Thu, 25 Apr 2019 18 : 59 : 45 + 0800 Thu, 25 Apr 2019 18 : 57 : 05 + 0800 KubeletReady kubelet is posting ready status Addresses: InternalIP: 10.81 . 163.21 Hostname: 10.81 . 163.21 Capacity: cpu: 4 ephemeral-storage: 41151808Ki hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 8008848Ki pods: 110 Allocatable: cpu: 3 ephemeral-storage: 35697000443 hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 5399696Ki pods: 110 System Info: Machine ID: 20190215172108590907433256076310 System UUID: 4F846BA6-A427- 4257 -91CF-E496FA5BCC45 Boot ID: eeb21388-45bf-429e-84a8-ff11a46833dd Kernel Version: 3.10 . 0 - 957.5 . 1 .el7.x86_64 OS Image: CentOS Linux 7 (Core) Operating System: linux Architecture: amd64 Container Runtime Version: docker: //18.3.1 Kubelet Version: v1. 13.1 Kube-Proxy Version: v1. 13.1 Non-terminated Pods: ( 8 in total) Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE --------- ---- ------------ ---------- --------------- ------------- --- ctet-sc ask-bar-service-vsv8z 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 5d22h ctet-sc ask-bar-web-server-h96dx 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 5d22h ctet-sc cs-service-vjgl5 100m ( 3 %) 4 ( 133 %) 1Gi ( 19 %) 2Gi ( 38 %) 39m ctet-sc exam-service-g442f 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 5d23h ctet-sc microclass-async-service-v7n8t 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 5d23h default node-server-7bnp5 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 0 ( 0 %) 8d default system-service-5584f55df5-hkv5t 1 ( 33 %) 6 ( 200 %) 1Gi ( 19 %) 6Gi ( 116 %) 12d monitoring node-exporter-4k4p2 112m ( 3 %) 270m ( 9 %) 200Mi ( 3 %) 220Mi ( 4 %) 29d Allocated resources: (Total limits may be over 100 percent, i.e., overcommitted.) Resource Requests Limits -------- -------- ------ cpu 1212m ( 40 %) 10270m ( 342 %) memory 2248Mi ( 42 %) 8412Mi ( 159 %) ephemeral-storage 0 ( 0 %) 0 ( 0 %) |
2.内存使用率=pod used total memory/Allocatable Memory=(5176*1024)/5399696=0.9816=98%
pod used total memory就是在这台机器上的所有docker容器占用内存总和;
Allocatable Memory就是kubectl describe no 查看出该节点可分配的内存=物理内存-k8s预留内存
同理cpu使用率=pod used total cpu/Allocatable CPU