Scale Vertically by Changing Requests and Limits · Kubernetes
Compare changing resources per Pod with changing the number of Pods.
Learn with progress and quizzesFirst, understand the concepts.
Vertical, horizontal, and node scaling
Vertical scaling adjusts per-container CPU and memory; horizontal scaling changes replicas; node scaling changes cluster capacity. Increasing requests does not automatically add CPUs or nodes.
Requests and limits
Requests guide placement and allocation; limits cap execution resources. CPU limits can cause throttling and memory excess can lead to OOM termination. 100m CPU means 0.1 CPU; 64Mi uses binary memory units.
Template updates replace Pods
Changing resources in a Deployment template triggers a rollout. This lab replaces Pods rather than performing in-place resize. Live Pod resize support depends on Kubernetes, feature configuration, runtime, and available resources.
Why it matters
Adding replicas differs from giving each instance more resources. First distinguish parallelizable work, CPU throttling, and memory pressure.
Work through the reasoning
Sum the requests
Two Pods requesting 50m each total 100m. Raising each to 100m totals 200m. Rolling-update surge may temporarily require additional capacity.
Read the result
set resources changes a Deployment template and produces replacement Pods. Compare replica count, per-Pod resources, and UIDs to demonstrate resizing with a fixed replica count.
Learn by doing.
Use kubectl, a personal practice Kubernetes cluster, and a POSIX shell. cert-manager and VPA labs require the components specified in each lesson. Node-changing labs require a dedicated disposable worker. Use the practice namespaces.
Use an ordinary personal practice cluster with capacity for two replicas. No metrics-server or VPA is required. Increase requests from 50m/32Mi to 100m/64Mi and adjust limits. Compare old and new Pod UIDs.
(
set -eu
kubectl config current-context
kubectl create namespace study-vertical --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -n study-vertical -f - <<'YAML'
apiVersion: apps/v1
kind: Deployment
metadata:
name: worker
spec:
replicas: 2
selector:
matchLabels: {app: vertical-worker}
template:
metadata:
labels: {app: vertical-worker}
spec:
containers:
- name: worker
image: busybox:1.36
command: ["sleep", "3600"]
resources:
requests: {cpu: 50m, memory: 32Mi}
limits: {cpu: 100m, memory: 64Mi}
YAML
kubectl rollout status deployment/worker -n study-vertical --timeout=120s
kubectl get pods -n study-vertical -o custom-columns=NAME:.metadata.name,UID:.metadata.uid,CPU:.spec.containers[0].resources.requests.cpu,MEMORY:.spec.containers[0].resources.requests.memory
kubectl set resources deployment worker -n study-vertical -c worker --requests=cpu=100m,memory=64Mi --limits=cpu=200m,memory=128Mi
kubectl rollout status deployment/worker -n study-vertical --timeout=120s
kubectl get deployment worker -n study-vertical -o jsonpath='{.spec.replicas}{"\n"}{.spec.template.spec.containers[0].resources}{"\n"}'
kubectl get pods -n study-vertical -o custom-columns=NAME:.metadata.name,UID:.metadata.uid,CPU:.spec.containers[0].resources.requests.cpu,MEMORY:.spec.containers[0].resources.requests.memory
)How to check your result
Keep spec.replicas at 2 while the new template requests 100m/64Mi with limits 200m/128Mi. Confirm Ready replicas after rollout; terminating old Pods may briefly remain listed. If replacements are Pending, investigate requests and rollout surge against available capacity.
Clean up practice resources
Run after checking the result. Confirm these resources belong to your practice run and contain no data you need to keep.
kubectl delete namespace study-verticalApply what you learned
The node has 150m request capacity left, but two Pods each need an extra 100m. What is the concern?
Reveal the reasoning after trying
The steady-state increase totals 200m and exceeds capacity; rollout surge may need more. Without capacity or an appropriate placement plan, replacements may remain Pending. Requests are not merely current utilization.
Ready to check your understanding?
Which observation demonstrates vertical scaling in this lab?
- Replicas increase from two to four
- Replicas stay at two while per-container requests increase
- A node appears automatically
- A Service port increases
Reveal the reasoning after trying
Replicas stay at two while per-container requests increase
The replica count stays fixed while resources per Pod change. Template changes replace Pods; performance improvement still requires workload and metric verification.
Official documentation · Scale Vertically by Changing Requests and Limits