Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 137Kubernetes · Operations

How to see CPU and memory of Pods and nodes

Which Pod eats the memory? Is the node full, or only "full" on paper because of big requests? kubectl top shows real usage, kubectl describe node shows what is reserved — you need both to understand a cluster. This how-to reads them, finds the top consumers, compares usage with requests, and explains why the numbers sometimes look strange.

  • 5 Lessen
  • 6 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

137.1

The quick answer

kubectl top nodes
NAME      CPU(cores)   CPU(%)   MEMORY(bytes)   MEMORY(%)
worker1   1840m        46%      9812Mi          63%
kubectl top pods -A --sort-by=memory | head -10
kubectl top pods -n shop --containers
kubectl describe node worker1 | grep -A10 'Allocated resources'

kubectl top needs metrics-server in the cluster.

137.2

Step by step

  1. Real usage — nodes and Pods (quick answer). --sort-by=cpu|memory puts the biggest at the top; --containers splits Pods into containers (app vs sidecar).
  2. Reserved (requests) vs real use:
kubectl describe node worker1 | grep -A10 'Allocated resources'
  Resource           Requests      Limits
  cpu                3650m (91%)   6 (150%)
  memory             12Gi (78%)    20Gi (130%)

This node is 91 % requested but only 46 % used — new Pods can not be scheduled although the CPU is half idle. The fix is better (lower) requests, not more nodes.

  1. Requests vs usage per Pod — find over- and under-sized apps:
kubectl get pods -n shop -o custom-columns=NAME:.metadata.name,CPU_REQ:.spec.containers[*].resources.requests.cpu,MEM_REQ:.spec.containers[*].resources.requests.memory
kubectl top pods -n shop
  1. Install metrics-server if kubectl top says Metrics API not available:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

(Pin a release version instead of latest for production. On kubeadm labs it may need --kubelet-insecure-tls; in production give the kubelets proper certificates.)

  1. History and trends — kubectl top shows only "now". For "since when does it grow?" use Prometheus + Grafana (kube-state-metrics and cAdvisor metrics), or k9s for a live view.

137.3

Check that it worked

You can name the top 5 Pods by memory and CPU, see for each node the usage and the requested share, and decide if the problem is real load or wrong requests.

137.4

Common problems

ProblemCauseFix
error: Metrics API not availableNo metrics-server.Install it; check its Pod logs.
metrics-server logs x509 errorskubelet serving certificates not trusted.Proper kubelet certs; --kubelet-insecure-tls only in labs.
Node "full" but CPU idleRequests far above real use.Lower requests from measured usage.
Memory % looks higher than free on the nodetop shows working set (incl. some cache).Normal; compare trends, not single numbers.
A Pod is missing in topIt just started (metrics every ~15–60 s) or is not running.Wait a minute; check the Pod status.
Numbers jump aroundShort sampling window.Use Prometheus for averages and percentiles.

137.5

Go further

1A node shows 91 % CPU requested but 46 % used. What does that mean?

The scheduler sees it as almost full because of high requests, though the CPU is half idle — lower the requests.

2What does kubectl top need in the cluster?

metrics-server.

Alle commando's in dit hoofdstuk