5

I've got some deployment on a basic k8s cluster withouth defining requests and limits. Is there any way to check how much the pod is asking for memory and cpu?

Manuel Castro
  • 1,633
  • 3
  • 24
  • 38
  • https://stackoverflow.com/questions/57731048/kubernetes-get-actual-resource-limits-inside-container It works even if you don't define requests and limits explicitly. – Dagang Sep 13 '19 at 14:29

2 Answers2

8

Depending on whether the metrics-server is installed in your cluster, you can use:

kubectl top pod
kubectl top node
Blokje5
  • 4,763
  • 1
  • 20
  • 37
  • I know about the "top" command. But I mean, how many resources the pod could request if I'm not defining limits? – Manuel Castro Sep 13 '19 at 14:32
  • If you are not defining requests and limits it can request as much as is available on the node. – Blokje5 Sep 13 '19 at 14:44
  • 1
    Ok, but how can I estimate the limits I should gave to a pod? If my container runs a server-side multithreading application should I gave to the pod 2 core as resources? Is there a kubernetes mechanism that split resources into cores? – Manuel Castro Sep 13 '19 at 14:51
  • https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu. 1000m translates to 1 CPU at most cloud providers. IF your container uses multi-threading it does not mean per se that it needs 2 full CPUs (unless it would utilise them fully). CPU is interpreted as the total amount of CPU time that a container can use every 100ms. – Blokje5 Sep 13 '19 at 14:56
  • Great! Thanks for claryfing me these things ;) Appreciate that – Manuel Castro Sep 13 '19 at 15:01
6

After installing the Metrics Server, you can query the Resource Metrics API directly for the resource usages of pods and nodes:

  • All nodes in the cluster:
    • kubectl get --raw=/apis/metrics.k8s.io/v1beta1/nodes
  • A specific node:
    • kubectl get --raw=/apis/metrics.k8s.io/v1beta1/nodes/{node}
  • All pods in the cluster:
    • kubectl get --raw=/apis/metrics.k8s.io/v1beta1/pods
  • All pods in a specific namespace:
    • kubectl get --raw=/apis/metrics.k8s.io/v1beta1/namespaces/{namespace}/pods
  • A specific pod:
    • kubectl get --raw=/apis/metrics.k8s.io/v1beta1/namespaces/{namespace}/pods/{pod}

The API returns you the absolute CPU and memory usages of the pods and nodes.

From this, you should be able to figure out how much resources each pod consumes and how much free resources are left on each node.

weibeld
  • 13,643
  • 2
  • 36
  • 50