Hi All, Can someone please suggest how to get the CPU & Memory usage informa . . .

Ram:
Hi All, Can someone please suggest how to get the CPU & Memory usage information for a pod or node? (Incase there is no metric server installed on the CKA exam environment).

RG:
Shouldn’t be the case, but kubectl describe nodes

RG:

root@kind-control-plane:/# k describe node 
Name:               kind-control-plane
Roles:              master
Labels:             <http://beta.kubernetes.io/arch=amd64|beta.kubernetes.io/arch=amd64>
                    <http://beta.kubernetes.io/os=linux|beta.kubernetes.io/os=linux>
                    <http://kubernetes.io/arch=amd64|kubernetes.io/arch=amd64>
                    <http://kubernetes.io/hostname=kind-control-plane|kubernetes.io/hostname=kind-control-plane>
                    <http://kubernetes.io/os=linux|kubernetes.io/os=linux>
                    <http://node-role.kubernetes.io/master=|node-role.kubernetes.io/master=>
Annotations:        <http://kubeadm.alpha.kubernetes.io/cri-socket|kubeadm.alpha.kubernetes.io/cri-socket>: unix:///run/containerd/containerd.sock
                    <http://node.alpha.kubernetes.io/ttl|node.alpha.kubernetes.io/ttl>: 0
                    <http://projectcalico.org/IPv4Address|projectcalico.org/IPv4Address>: 172.18.0.4/16
                    <http://projectcalico.org/IPv4VXLANTunnelAddr|projectcalico.org/IPv4VXLANTunnelAddr>: 10.244.82.0
                    <http://volumes.kubernetes.io/controller-managed-attach-detach|volumes.kubernetes.io/controller-managed-attach-detach>: true
CreationTimestamp:  Thu, 24 Dec 2020 15:21:50 +0000
Taints:             <http://node-role.kubernetes.io/master:NoSchedule|node-role.kubernetes.io/master:NoSchedule>
Unschedulable:      false
Lease:
  HolderIdentity:  kind-control-plane
  AcquireTime:     &lt;unset&gt;
  RenewTime:       Fri, 25 Dec 2020 16:45:51 +0000
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Fri, 25 Dec 2020 09:58:46 +0000   Fri, 25 Dec 2020 09:58:46 +0000   CalicoIsUp                   Calico is running on this node
  MemoryPressure       False   Fri, 25 Dec 2020 16:43:58 +0000   Thu, 24 Dec 2020 15:21:48 +0000   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Fri, 25 Dec 2020 16:43:58 +0000   Thu, 24 Dec 2020 15:21:48 +0000   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Fri, 25 Dec 2020 16:43:58 +0000   Thu, 24 Dec 2020 15:21:48 +0000   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Fri, 25 Dec 2020 16:43:58 +0000   Thu, 24 Dec 2020 15:26:24 +0000   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  172.18.0.4
  Hostname:    kind-control-plane
Capacity:
  cpu:                12
  ephemeral-storage:  751155104Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             32496380Ki
  pods:               110
Allocatable:
  cpu:                12
  ephemeral-storage:  751155104Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             32496380Ki
  pods:               110
System Info:
  Machine ID:                 6ab076c1970c42e495989b45e0207d11
  System UUID:                01ac5ffa-b786-458d-abde-f51a401218d2
  Boot ID:                    e52c154a-b8c8-400d-bd3f-33b8ffd89cab
  Kernel Version:             5.8.0-33-generic
  OS Image:                   Ubuntu Groovy Gorilla (development branch)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  <containerd://1.4.0>
  Kubelet Version:            v1.19.1
  Kube-Proxy Version:         v1.19.1
PodCIDR:                      10.244.0.0/24
PodCIDRs:                     10.244.0.0/24
ProviderID:                   <kind://docker/kind/kind-control-plane>
Non-terminated Pods:          (8 in total)
  Namespace                   Name                                          CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                   ----                                          ------------  ----------  ---------------  -------------  ---
  calico-system               calico-node-zkdkw                             0 (0%)        0 (0%)      0 (0%)           0 (0%)         25h
  calico-system               calico-typha-6d95dffd49-qg7zj                 0 (0%)        0 (0%)      0 (0%)           0 (0%)         25h
  kube-system                 coredns-f9fd979d6-t4m9q                       100m (0%)     0 (0%)      70Mi (0%)        170Mi (0%)     25h
  kube-system                 etcd-kind-control-plane                       0 (0%)        0 (0%)      0 (0%)           0 (0%)         7h18m
  kube-system                 kube-apiserver-kind-control-plane             250m (2%)     0 (0%)      0 (0%)           0 (0%)         7h18m
  kube-system                 kube-controller-manager-kind-control-plane    200m (1%)     0 (0%)      0 (0%)           0 (0%)         25h
  kube-system                 kube-proxy-xl7pw                              0 (0%)        0 (0%)      0 (0%)           0 (0%)         25h
  kube-system                 kube-scheduler-kind-control-plane             100m (0%)     0 (0%)      0 (0%)           0 (0%)         25h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests   Limits
  --------           --------   ------
  cpu                650m (5%)  0 (0%)
  memory             70Mi (0%)  170Mi (0%)
  ephemeral-storage  0 (0%)     0 (0%)
  hugepages-1Gi      0 (0%)     0 (0%)
  hugepages-2Mi      0 (0%)     0 (0%)
Events:              &lt;none&gt;

PP:
@Ram I found https://stackoverflow.com/questions/54531646/checking-kubernetes-pod-cpu-and-memory

If you want to check pods cpu/memory usage without installing any third party tool then you can get memory and cpu usage of pod from cgroup.

  1. Go to pod’s exec mode kubectl exec pod_name -- /bin/bash
  2. Go to cd /sys/fs/cgroup/cpu for cpu usage run cat cpuacct.usage
  3. Go to cd /sys/fs/cgroup/memory for memory usage run cat memory.usage_in_bytes
    I didn’t tried. You can give a try

RG:
Those are where the programs most probably get their info from. but for a quick table:

Non-terminated Pods:          (8 in total)
  Namespace                   Name                                          CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                   ----                                          ------------  ----------  ---------------  -------------  ---
  calico-system               calico-node-zkdkw                             0 (0%)        0 (0%)      0 (0%)           0 (0%)         25h
  calico-system               calico-typha-6d95dffd49-qg7zj                 0 (0%)        0 (0%)      0 (0%)           0 (0%)         25h
  kube-system                 coredns-f9fd979d6-t4m9q                       100m (0%)     0 (0%)      70Mi (0%)        170Mi (0%)     25h
  kube-system                 etcd-kind-control-plane                       0 (0%)        0 (0%)      0 (0%)           0 (0%)         7h18m
  kube-system                 kube-apiserver-kind-control-plane             250m (2%)     0 (0%)      0 (0%)           0 (0%)         7h18m
  kube-system                 kube-controller-manager-kind-control-plane    200m (1%)     0 (0%)      0 (0%)           0 (0%)         25h
  kube-system                 kube-proxy-xl7pw                              0 (0%)        0 (0%)      0 (0%)           0 (0%)         25h
  kube-system                 kube-scheduler-kind-control-plane             100m (0%)     0 (0%)      0 (0%)           0 (0%)         25h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests   Limits
  --------           --------   ------
  cpu                650m (5%)  0 (0%)
  memory             70Mi (0%)  170Mi (0%)
  ephemeral-storage  0 (0%)     0 (0%)
  hugepages-1Gi      0 (0%)     0 (0%)
  hugepages-2Mi      0 (0%)     0 (0%)

RG:
kubectl describe node nodename does it

Ram:
Thanks @RG - Is it safe to assume that the metric server will be pre-installed for such questions?

Ram:
Thanks @PP. Yes, I too saw that thread but for some reasons the results didnt match in my case. The value in the file and the result of metric server was different

RG:
if they want you to get readings, they will have it preinstalled, or at the very least you’ll be given a command to install it, like the CNI

Ram:
ok great then. Thanks again @RG