Skip to main content
RunBook Academy

KubernetesLXXXIV · Resource Capacity PlanningCapacity planning

Right-sizing — the discipline of resource optimization

Advanced⏱ ~12 minkubectlvpaprometheus

What you'll learn

  • Explain the right-sizing discipline
  • Use VPA for right-sizing
  • Use kubectl top and Prometheus for analysis
  • Plan the right-sizing workflow

Prerequisites

Verified against Kubernetes 1.34.x · kubeadm 1.34.x · kubectl 1.34.x · etcd 3.6.x · CoreDNS 1.11.x · containerd 1.7.x / 2.x · 2026-08-16

Not yet marked complete on this device.

Right-sizing is the discipline of keeping the workload’s resources aligned with the actual usage. The tools (VPA, kubectl top, Prometheus), the timing (continuous), and the workflow (analyze, configure, validate) are the inputs. This lesson walks the discipline, the tools, the timing, and the production patterns.

The right-sizing discipline

The right-sizing discipline is the act of:

  1. Analyze: measure the workload’s actual usage.
  2. Configure: set the requests to match the actual usage.
  3. Validate: verify the new requests are correct.

The discipline is continuous; the workload’s usage changes over time.

flowchart LR
    A[Analyze usage] --> B[Configure requests]
    B --> C[Validate]
    C --> A

The cycle is continuous.

The tools

The tools for right-sizing:

The VPA

The VPA (Part LXXXIII) is the canonical tool:

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: nginx-vpa
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: nginx
      minAllowed:
        cpu: 100m
        memory: 128Mi
      maxAllowed:
        cpu: 2
        memory: 4Gi

The VPA computes the recommendations and updates the pods.

The kubectl top

The kubectl top is the quick inspector:

kubectl top pods -A
NAMESPACE   NAME                              CPU(cores)   MEMORY(bytes)
default     nginx-1-abc                       100m         128Mi
default     nginx-2-def                       120m         130Mi

The output shows the current usage.

The Prometheus

The Prometheus is the historical inspector:

# Average CPU usage over the past 7 days
avg_over_time(
  rate(container_cpu_usage_seconds_total{pod=~"nginx-.*"}[5m])[7d:5m]
)

The Prometheus query gives the historical view.

The timing

The right-sizing timing is continuous:

flowchart LR
    A[Continuous monitoring] --> B[Daily review]
    B --> C[Weekly review]
    C --> D[Quarterly review]

The reviews are the cadence. The right-sizing is the output.

The workflow

The right-sizing workflow:

sequenceDiagram
    participant O as Operator
    participant V as VPA
    participant P as Prometheus
    participant C as Cluster
    O->>P: analyze usage
    P-->>O: usage data
    O->>V: configure VPA
    V->>C: update pod requests
    C-->>O: validation result
    O->>O: document the right-sizing

The workflow is per workload.

The analysis

The analysis uses the metrics:

# Per-workload CPU usage (95th percentile)
quantile_over_time(0.95,
  rate(container_cpu_usage_seconds_total{pod=~"nginx-.*"}[5m])[7d:1h]
)

The 95th percentile is the analysis target.

nginx-1-abc: 95th percentile CPU = 250m
nginx-2-def: 95th percentile CPU = 280m
nginx-3-ghi: 95th percentile CPU = 270m

The analysis is the input for the right-sizing.

The configuration

The configuration uses the VPA:

resourcePolicy:
  containerPolicies:
  - containerName: nginx
    minAllowed:
      cpu: 100m
      memory: 128Mi
    maxAllowed:
      cpu: 1
      memory: 2Gi

The VPA’s recommendations are bounded.

The validation

The validation verifies the right-sizing:

# Check the VPA recommendation
kubectl describe vpa nginx-vpa

# Check the pod's actual requests
kubectl get pod nginx-1-abc -o jsonpath='{.spec.containers[0].resources.requests}'

# Run the workload
hey -z 5m -c 100 http://nginx/

# Check the actual usage
kubectl top pods -A

The validation confirms the right-sizing is correct.

The production patterns

The production patterns:

  • Daily review: the VPA recommendation is inspected. The recommendations are applied if needed.
  • Weekly review: the cluster utilization is analyzed. The right-sizing opportunities are identified.
  • Quarterly review: the capacity plan is updated. The cost projections are updated.

The documentation

The right-sizing is documented:

WORKLOAD: nginx
WORKLOAD CLASS: Stateful (no, stateless)
REQUEST HISTORY:
  - 2026-01-01: 100m / 128Mi
  - 2026-04-01: 200m / 256Mi (VPA recommendation)
  - 2026-08-01: 250m / 320Mi (VPA recommendation)
USAGE (95th percentile):
  - CPU: 250m
  - Memory: 320Mi
NEXT REVIEW: 2026-11-01

The documentation is the audit trail.

Cross-course references

  • The VPA course (Part LXXXIII) covers the right-sizing.
  • The HPA course (Part LXXXII) covers the scaling.
  • The Prometheus course (Part LXXXVIII) covers the metrics.

Quiz

Knowledge check · 4 questions

  1. Q1. Which is the canonical tool for right-sizing Kubernetes workloads?

  2. Q2. Right-sizing is a one-time activity at cluster creation.

  3. Q3. Walk the right-sizing workflow for a production workload.

    Deployment nginx with 5 replicas. The current requests are 1 vCPU / 2Gi memory per pod. The Prometheus metrics show the actual usage is 250m / 320Mi. The team is right-sizing.

  4. Q4. What is the right-sizing cadence in production?

Passing score: 75%. Answers are checked in this browser.

Production discipline

  • Use VPA for right-sizing. The canonical tool.
  • Inspect the recommendations daily. The VPA is the source.
  • Analyze the cluster utilization weekly. The Prometheus is the source.
  • Review the capacity plan quarterly. The spreadsheet is the deliverable.
  • Document the right-sizing. The audit trail.
  • Test the right-sizing. Use load generation to verify.

The right-sizing is the workload’s financial discipline. Operating it well is keeping the requests aligned with the actual usage, using the VPA, and documenting the changes.