← Recipes

阅读中文版本

Right-Size Pods with the Vertical Pod Autoscaler

Run VPA in recommendation mode first, review suggested requests and limits, then enable it in a controlled mode so pods get resources matching real usage.

~40 minkubernetesautoscalingperformance

Task

Use VPA to size CPU and memory requests from observed usage instead of guesswork.

When to use this

Requests are guessed, so pods are either throttled or over-provisioned, and the cluster cannot schedule efficiently.

Prerequisites

  • VPA installed in the cluster
  • A metrics server

Steps

1. Deploy VPA in Off mode to gather recommendations without changing pods.

Expected output: You see suggested requests from real usage.

2. Review recommendations against SLOs and known peaks.

Expected output: Suggestions are sanity-checked, not blindly applied.

3. Enable in Initial or Recreate mode for suitable workloads.

Expected output: Pods are sized to real usage.

4. Monitor for restarts caused by VPA and exclude stateful or latency-critical pods if needed.

kubectl describe vpa app-vpa

Expected output: Right-sizing does not cause churn.

Troubleshooting

Problem

VPA restarts pods too often

Solution

VPA changes requests by evicting; use Off for advice and apply changes manually for sensitive workloads.

Problem

VPA conflicts with HPA

Solution

Do not let VPA target CPU while HPA scales on CPU; split the dimensions.

Limitations

  • VPA in acting modes can evict pods to apply new requests, causing disruption.
  • It reacts to past usage and cannot anticipate traffic spikes the way horizontal scaling can.

Context

Use VPA to size CPU and memory requests from observed usage instead of guesswork. Requests are guessed, so pods are either throttled or over-provisioned, and the cluster cannot schedule efficiently.

Steps

  1. Deploy VPA in Off mode to gather recommendations without changing pods. Expected: You see suggested requests from real usage.
  2. Review recommendations against SLOs and known peaks. Expected: Suggestions are sanity-checked, not blindly applied.
  3. Enable in Initial or Recreate mode for suitable workloads. Expected: Pods are sized to real usage.
  4. Monitor for restarts caused by VPA and exclude stateful or latency-critical pods if needed. Expected: Right-sizing does not cause churn.
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata: { name: app-vpa }
spec:
  targetRef: { apiVersion: apps/v1, kind: Deployment, name: app }
  updatePolicy: { updateMode: "Off" }  # recommendation only

Verify

  • You see suggested requests from real usage.
  • Suggestions are sanity-checked, not blindly applied.
  • Pods are sized to real usage.
  • Right-sizing does not cause churn.

Limits

  • VPA in acting modes can evict pods to apply new requests, causing disruption.
  • It reacts to past usage and cannot anticipate traffic spikes the way horizontal scaling can.