List Resource Requests and Limits for Kubernetes pods (Misc)

Running kubectl get pods is pretty straightfoward, but it can do also do a lot of filtering

If you've ended up with fewer pods per node than expected, it's worth looking at what resources are being requested. Similarly, if you're seeing a high rate of evictions, it's worth looking at what the limits are

This snippet details listing requests and limits, per pod, on a node

Note: if you have, or are able to install the kubectl-ice plugin it's a far superior method because it can also show you what's actually been used.

Details

  • Language: Misc

Snippet

# Without kubectl-ice
kubectl get -A pods \
--field-selector spec.nodeName="$NODE" \
-o custom-columns='NAME:.metadata.name, CPU_REQUEST:.spec.containers[*].resources.requests.cpu, CPU_LIMIT:.spec.containers[*].resources.limits.cpu, MEMORY_REQUEST:.spec.containers[*].resources.requests.memory, MEMORY_LIMIT:.spec.containers[*].resources.limits.memory'

# With kubectl-ice
kubectl ice memory --select nodeName=$NODE --sort USED --show-namespace -A
kubectl ice cpu --select nodeName=$NODE --sort USED --show-namespace -A

# Limiting kubectl-ice to an app rather than a node
kubectl ice memory -l app=foo --sort USED --show-namespace -A
kubectl ice cpu -l app=foo --sort USED --show-namespace -A