Kubernetes cookbook · Intermediate

Right-size requests with VPA recommendations

Requests were guessed at launch; find better values from real usage without risking restarts.

Create a free account to save this page, take notes and track your progress. Sign in

Approach

Install the Vertical Pod Autoscaler and create a VPA in recommendation-only mode (updateMode: "Off"). After a representative period, read the recommended requests and apply them through your normal deployment process.

Solution

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata: {name: api}
spec:
  targetRef: {apiVersion: apps/v1, kind: Deployment, name: api}
  updatePolicy: {updateMode: "Off"}
  resourcePolicy:
    containerPolicies:
      - containerName: api
        minAllowed: {cpu: 50m, memory: 128Mi}
        maxAllowed: {cpu: "2", memory: 4Gi}
kubectl get vpa api -o jsonpath='{.status.recommendation.containerRecommendations[0].target}'

Pitfalls

  • Letting VPA update pods automatically while an HPA scales on the same CPU or memory metric; they fight.
  • Reading recommendations after a quiet weekend; observe peaks too.

Variations

  • Goldilocks to view VPA recommendations for every workload in a dashboard.
  • In-place pod resize to change requests without restarting pods where supported.

Further reading: Vertical Pod Autoscaling

Reference: https://kubernetes.io/docs/concepts/workloads/autoscaling/vertical-pod-autoscale/

More Kubernetes recipes

Was this page helpful?