Getting CPU and Memory hard limit count in Kubernetes

10/10/2019

I am using different opensource components by pulling helm charts and installing. Now, after some time while deploying one custom helm chart I am getting resources unavailable. So, rather than counting manually is there any way to know total reserved resources.

So, How to get total reserved CPU and memory reserved by Kubernetes deployments/daemonsets/statefulsets.

(where limits and requests for cpu and memory is same)

-- rajdeepbs29
kubernetes

2 Answers

12/6/2019

I ran the below command to get the same. I hope it solves the issue quite easily.

alias util='kubectl get nodes --no-headers | awk '\''{print $1}'\'' | xargs -I {} sh -c '\''echo {} ; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve -- ; echo '\'''

[mynode ~]# util

my-control-01 Resource Requests Limits cpu 3683m (46%) 6848m (85%) memory 5188Mi (21%) 8370Mi (35%)

my-edge-01 Resource Requests Limits cpu 4 (100%) 16 (400%) memory 1Gi (13%) 4Gi (53%)

my-edge-02 Resource Requests Limits cpu 4 (100%) 16 (400%) memory 1Gi (13%) 4Gi (53%)

my-worker-01 Resource Requests Limits cpu 7810m (97%) 27750m (346%) memory 11066329600 (66%) 20814538Ki (128%)

my-worker-02 Resource Requests Limits cpu 6051m (75%) 13160m (164%) memory 12554Mi (79%) 17728Mi (112%)

-- rajdeepbs29
Source: StackOverflow

10/10/2019

did you try below command

# kubectl top nodes
NAME                       CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
aks-agentpool-23045933-0   333m         17%    2372Mi          52%       
aks-agentpool-23045933-2   178m         9%     2396Mi          52%       
aks-agentpool-23045933-3   276m         14%    2724Mi          59%       
aks-agentpool-23045933-4   100m         5%     1965Mi          43% 
look at 
https://github.com/dpetzold/kube-resource-explorer

[root@91c8429db328 /]# kube-resource-explorer -namespace kube-system -reverse -sort MemReq
Namespace    Name                                                                                                                     CpuReq        CpuReq%  CpuLimit     CpuLimit%  MemReq           MemReq%  MemLimit         MemLimit%
---------    ----                                                                                                                     ------        -------  --------     ---------  ------           -------  --------         ---------
kube-system  calico-node-6n974/calico-node                                                                                            250m          1%       0m           0%         0Mi              0%       0Mi              0%
kube-system  addon-http-application-routing-nginx-ingress-controller-6bshkzj/addon-http-application-routing-nginx-ingress-controller  0m            0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  calico-node-kjwhc/calico-node                                                                                            250m          1%       0m           0%         0Mi              0%       0Mi              0%
kube-system  calico-typha-7f8cb769f7-kjqj4/calico-typha                                                                               0m            0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  calico-typha-horizontal-autoscaler-79d4669c84-fsjsb/autoscaler                                                           10m           0%       10m          0%         0Mi              0%       0Mi              0%
kube-system  kube-proxy-sv2zh/kube-proxy                                                                                              100m          0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  kube-proxy-c6f8t/kube-proxy                                                                                              100m          0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  metrics-server-58699455bc-tzzcw/metrics-server                                                                           0m            0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  calico-node-mcv8x/calico-node                                                                                            250m          1%       0m           0%         0Mi              0%       0Mi              0%
kube-system  tiller-deploy-5b7c66d59c-bxhhz/tiller                                                                                    0m            0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  kube-proxy-2rgsb/kube-proxy                                                                                              100m          0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  addon-http-application-routing-external-dns-696b566559-lt4gr/addon-http-application-routing-external-dns                 0m            0%       0m           0%         0Mi              0%       0Mi              0%
kube-system  coredns-autoscaler-657d77ffbf-wrrtm/autoscaler                                                                           20m           0%       0m           0%         10Mi             0%       0Mi              0%
kube-system  addon-http-application-routing-default-http-backend-74698cpmcg9/addon-http-application-routing-default-http-backend      10m           0%       10m          0%         20Mi             0%       20Mi             0%
kube-system  kubernetes-dashboard-6f697bd9f5-jjl5l/main                                                                               100m          0%       100m         0%         50Mi             0%       500Mi            0%
kube-system  tunnelfront-669ccdff9b-rpmd2/tunnel-front                                                                                10m           0%       0m           0%         64Mi             0%       0Mi              0%
kube-system  coredns-69b5b66fd8-r9z46/coredns                                                                                         100m          0%       0m           0%         70Mi             0%       170Mi            0%
kube-system  coredns-69b5b66fd8-7bbsk/coredns                                                                                         100m          0%       0m           0%         70Mi             0%       170Mi            0%
kube-system  omsagent-8q6hf/omsagent                                                                                                  75m           0%       150m         0%         225Mi            0%       600Mi            1%
kube-system  omsagent-z86h8/omsagent                                                                                                  75m           0%       150m         0%         225Mi            0%       600Mi            1%
kube-system  omsagent-z27df/omsagent                                                                                                  75m           0%       150m         0%         225Mi            0%       600Mi            1%
kube-system  omsagent-rs-878b9cbf4-4hpn4/omsagent                                                                                     110m          0%       150m         0%         250Mi            0%       500Mi            0%
kube-system  cluster-autoscaler-7ff7ff7d8c-6vgdb/cluster-autoscaler                                                                   100m          0%       200m         1%         300Mi            0%       500Mi            0%
---------    ----                                                                                                                     ------        -------  --------     ---------  ------           -------  --------         ---------
Total                                                                                                                                 1835m/47673m  3%       920m/47673m  1%         1509Mi/151406Mi  0%       3660Mi/151406Mi  2%
-- P Ekambaram
Source: StackOverflow