Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Kubernetes

Kubernetes: Use VPA to Automatically Adjust CPU/Memory Requests

- 31.05.26 - ErcanOPAK

📈 HPA Scales Pods. VPA Scales Pod Resources.

Guessing CPU/memory requests is hard. Vertical Pod Autoscaler recommends or automatically adjusts resource requests based on actual usage.

📝 Install VPA

git clone https://github.com/kubernetes/autoscaler.git
cd autoscaler/vertical-pod-autoscaler
./hack/vpa-up.sh

kubectl get pods -n kube-system | grep vpa

🎯 VPA Configuration

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: myapp-vpa
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  updatePolicy:
    updateMode: "Auto"  # or "Off", "Initial", "Recreate"
  resourcePolicy:
    containerPolicies:
    - containerName: '*'
      minAllowed:
        cpu: 100m
        memory: 256Mi
      maxAllowed:
        cpu: 2
        memory: 4Gi

# updateMode:
# - Off: Only recommendations, no changes
# - Initial: Set requests at creation only
# - Auto: Automatically update pods (may restart)
# - Recreate: Restart pods when needed

✅ Check Recommendations

kubectl describe vpa myapp-vpa

# Output shows:
# Recommendation:
#   Container Recommendations:
#     Container Name:  myapp
#     Lower Bound:     cpu: 250m, memory: 512Mi
#     Target:          cpu: 500m, memory: 1Gi
#     Upper Bound:     cpu: 1,    memory: 2Gi
#     Uncapped Target: cpu: 800m, memory: 1.5Gi

# Apply recommendations manually
kubectl edit deployment myapp
# Update requests to match Target values

💡 Best Practices

  • Start with updateMode: “Off” to see recommendations first
  • Set minAllowed to prevent under-provisioning
  • Set maxAllowed to prevent runaway pods
  • Don’t use VPA with HPA on same metrics (CPU/memory)
  • VPA may restart pods to apply changes

“Guessed CPU requests: 2 cores (over-provisioned). VPA recommended 500m. Saved 75% CPU cost. Memory recommendations saved another 50%. VPA paid for itself in a week.”

— FinOps Engineer

Related posts:

Readiness vs Liveness — One Mistake Takes Down Clusters

Kubernetes: Use kubectl port-forward to Debug Services Locally

Kubernetes — Liveness Probes Can Kill Healthy Pods

Post Views: 5

Post navigation

WordPress: WP_Query Best Practices to Avoid Performance Pitfalls
Docker: Use Docker Scout to Find Vulnerabilities in Your Images

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

June 2026
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  
« May    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (882)
  • Get the First and Last Word from a String or Sentence in SQL (838)
  • How to select distinct rows in a datatable in C# (808)
  • How to make theater mode the default for Youtube (805)
  • Add Constraint to SQL Table to ensure email contains @ (580)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (579)
  • Average of all values in a column that are not zero in SQL (538)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (505)
  • Find numbers with more than two decimal places in SQL (454)

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files
  • Ajax: Add Custom Headers to Fetch Requests
  • JavaScript: Use console.table to Display Arrays as Tables
  • HTML: Use Spellcheck Attribute to Enable Browser Spell Check
  • CSS: Use user-select to Prevent Text Selection
  • Windows 11: Use Snipping Tool for Instant Screenshots

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (882)
  • Get the First and Last Word from a String or Sentence in SQL (838)
  • How to select distinct rows in a datatable in C# (808)
  • How to make theater mode the default for Youtube (805)

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com