Skip to main content
Welcome — in this lab you’ll see the Vertical Pod Autoscaler (VPA) in action for tuning memory requests based on observed usage. This walkthrough covers deploying a sample Flask app, observing baseline memory, applying a memory-only VPA, and validating recommendations under load.
A presentation slide titled "VPA Memory Lab" showing a four-step workflow (01: Deploy sample application; 02: Monitor application resource usage; 03: Apply VPA configuration and capture recommendations; 04: Conduct initial load test to validate VPA recommendations) alongside a pink computer icon. The slide is branded with a KodeKloud copyright.
Overview — what you’ll do
  • Deploy a simple Flask application and a Kubernetes Service.
  • Observe pods and current CPU/memory usage to establish a baseline.
  • Create a VPA object targeting the Flask Deployment to collect memory recommendations.
  • Generate load and observe how VPA recommendations update.
Quick workflow
  1. Deploy the sample application.
  2. Monitor memory usage (baseline).
  3. Apply the VPA manifest (memory-only policy).
  4. Run a load test and re-check recommendations.
Prerequisites
  • A Kubernetes cluster with kubectl configured for your context.
  • metrics-server or other metrics provider installed to view pod resource usage (kubectl top pods).
  • VPA components (CRD + controller: recommender, updater, admission-controller if needed) installed so the VerticalPodAutoscaler resource can produce recommendations.
Deploy and inspect the sample application
  • After deploying the Flask app and Service, confirm pods are running:
Example output:
  • Check current memory usage (with metrics-server):
Note typical baseline memory consumption (example: ~19Mi) so you can compare before/after load. VPA configuration used in this lab
  • This VPA manifest is configured to provide memory recommendations only. It sets minAllowed and maxAllowed memory bounds and uses updateMode: Off so changes are recommendations only.
This VPA is restricted to memory recommendations (controlledResources). With updateMode: "Off", VPA only reports recommendations — it will not modify pod resource requests automatically.
Apply the VPA manifest
Ensure the VPA CRD/controller are installed, otherwise the resource may be unrecognized or will not produce recommendations. Example create output:
If the VPA controller or CRD is missing, kubectl get vpa may return “no resources found” or the resource may appear but never populate status.recommendation. Install the VPA components from the official project before proceeding: https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler
Inspecting VPA recommendations (before load)
  • Get the VPA object to view recommendations:
  • Immediately after creation (before load) you may see recommendations that reflect current usage and your configured bounds. Example snippet:
Key recommendation fields (summary) Generating load and re-checking recommendations
  • Run the provided load script to stress the Flask app:
Example output:
  • Let the load run long enough for the recommender to observe increased memory usage, then re-check VPA:
Example updated recommendation after load:
Interpreting recommendations after load
  • target and uncappedTarget increase to match observed memory usage (example: ~512Mi).
  • If uncappedTarget stays within maxAllowed, VPA’s effective recommendation will equal the uncapped recommendation.
  • If uncappedTarget exceeds maxAllowed (e.g., uncapped 1200Mi while maxAllowed = 1000Mi), VPA will cap the recommendation at maxAllowed. Decide whether to raise maxAllowed if your app legitimately needs more memory, or consider horizontal scaling (more replicas) instead of a single larger instance.
Practical considerations and best practices
  • Use updateMode: "Off" in production if you require manual review before applying resource changes.
  • Large memory allocations can impact node packing and garbage collection — review node capacity and application behavior before increasing memory limits.
  • VPA is best for adjusting requests for workloads that benefit from vertical scaling (single-pod improvement). For horizontally scalable services, prefer Horizontal Pod Autoscaler (HPA) or combine VPA with HPA carefully.
  • Always verify metrics collection (e.g., metrics-server) and VPA controller health to ensure accurate recommendations.
Useful links and references This finishes the conceptual walkthrough for the VPA Memory Lab. In the hands-on lab you will perform these steps and observe how recommendations change between baseline and under load.

Watch Video

Practice Lab