Skip to content
Latchkey

kubectl set resources: Usage, Options & Common CI Errors

Adjust CPU and memory requests and limits without editing YAML.

kubectl set resources patches the requests and limits on a container, triggering a rolling update. It is used in CI to right-size a workload or to bump limits before a load test.

What it does

kubectl set resources deploy/NAME --requests=cpu=200m,memory=256Mi --limits=cpu=500m,memory=512Mi patches the container's resource block. -c selects a container; --limits and --requests can be set independently. CPU is in cores or millicores (500m), memory in Ki/Mi/Gi.

Common usage

Terminal
kubectl set resources deploy/web -c=web --limits=cpu=500m,memory=512Mi
kubectl set resources deploy/web --requests=cpu=200m,memory=256Mi
kubectl set resources deploy/web -c=web \
  --requests=cpu=200m,memory=256Mi --limits=cpu=1,memory=1Gi

Common errors in CI

The classic trap is requesting more than any node can offer: the new pods sit Pending with "0/N nodes are available: N Insufficient cpu/memory" and the rollout stalls until its deadline - describe the pod to see it, and lower the request or add capacity. A namespace LimitRange or ResourceQuota can reject the patch outright ("must be less than or equal to ...max" or "exceeded quota"). Setting a memory limit below actual usage gets the container OOMKilled on the next spike. Always follow set resources with kubectl rollout status so a bad sizing fails the deploy.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →