|
| 1 | +# AEP-XXXX: MemoryPerCPU |
| 2 | + |
| 3 | +<!-- toc --> |
| 4 | +- [Summary](#summary) |
| 5 | +- [Motivation](#motivation) |
| 6 | + - [Goals](#goals) |
| 7 | + - [Non-Goals](#non-goals) |
| 8 | +- [Proposal](#proposal) |
| 9 | +- [Design Details](#design-details) |
| 10 | + - [API Changes](#api-changes) |
| 11 | + - [Behavior](#behavior) |
| 12 | + - [Feature Enablement and Rollback](#feature-enablement-and-rollback) |
| 13 | + - [How can this feature be enabled / disabled in a live cluster?](#how-can-this-feature-be-enabled--disabled-in-a-live-cluster) |
| 14 | + - [Kubernetes Version Compatibility](#kubernetes-version-compatibility) |
| 15 | + - [Validation](#validation) |
| 16 | + - [Test Plan](#test-plan) |
| 17 | +- [Implementation History](#implementation-history) |
| 18 | +- [Future Work](#future-work) |
| 19 | +- [Alternatives](#alternatives) |
| 20 | + <!-- /toc --> |
| 21 | + |
| 22 | +## Summary |
| 23 | + |
| 24 | +This AEP proposes a new feature to allow enforcing a fixed memory-per-CPU ratio (`memoryPerCPU`) in Vertical Pod Autoscaler (VPA) recommendations. |
| 25 | +The feature is controlled by a new alpha feature gate `MemoryPerCPURatio` (default off). |
| 26 | + |
| 27 | +## Motivation |
| 28 | + |
| 29 | +Many workloads scale their memory requirements proportionally to CPU. Today, VPA independently recommends CPU and memory, which can result in skewed recommendations (too much memory for small CPU, or too little memory for high CPU). |
| 30 | + |
| 31 | +By introducing `memoryPerCPU`, users can enforce a predictable ratio between CPU and memory, reducing risk of misconfiguration and simplifying tuning for ratio-based workloads. |
| 32 | + |
| 33 | +In addition, some environments or organizations prefer to keep a fixed CPU-to-memory ratio for reasons such as: |
| 34 | +* **Billing models** – Many cloud providers price instances based on predefined CPU/memory bundles. Enforcing a fixed ratio makes VPA recommendations align better with billing units, avoiding unexpected cost patterns. |
| 35 | +* **Operational simplicity** – A consistent CPU/memory ratio across workloads reduces variability and simplifies capacity planning. |
| 36 | + |
| 37 | +### Goals |
| 38 | + |
| 39 | +* Allow users to specify a `memoryPerCPU` ratio in `VerticalPodAutoscaler` objects. |
| 40 | +* Ensure VPA recommendations respect the ratio across Target, LowerBound, UpperBound, and UncappedTarget. |
| 41 | +* Provide a feature gate to enable/disable the feature cluster-wide. |
| 42 | + |
| 43 | +### Non-Goals |
| 44 | + |
| 45 | +* Redesign of the VPA recommender algorithm beyond enforcing the ratio. |
| 46 | +* Supporting multiple ratio policies per container (only one `memoryPerCPU` is supported). |
| 47 | +* Retroactive migration of existing VPAs without explicit user opt-in. |
| 48 | + |
| 49 | +## Proposal |
| 50 | + |
| 51 | +Extend `ContainerResourcePolicy` with a new optional field: |
| 52 | + |
| 53 | +```yaml |
| 54 | +apiVersion: autoscaling.k8s.io/v1 |
| 55 | +kind: VerticalPodAutoscaler |
| 56 | +metadata: |
| 57 | + name: my-app |
| 58 | +spec: |
| 59 | + resourcePolicy: |
| 60 | + containerPolicies: |
| 61 | + - containerName: app |
| 62 | + minAllowed: |
| 63 | + cpu: 1 |
| 64 | + memory: 4Gi |
| 65 | + maxAllowed: |
| 66 | + cpu: 4 |
| 67 | + memory: 16Gi |
| 68 | + controlledResources: ["cpu", "memory"] |
| 69 | + controlledValues: RequestsAndLimits |
| 70 | + memoryPerCPU: "4Gi" |
| 71 | +``` |
| 72 | +
|
| 73 | +When enabled, VPA will adjust CPU or memory recommendations to maintain: |
| 74 | +
|
| 75 | +``` |
| 76 | +memory_bytes = cpu_cores * memoryPerCPU |
| 77 | +``` |
| 78 | + |
| 79 | +## Design Details |
| 80 | + |
| 81 | +### API Changes |
| 82 | + |
| 83 | +* New field `memoryPerCPU` (`resource.Quantity`) in `ContainerResourcePolicy`. |
| 84 | +* Feature gate: `MemoryPerCPURatio` (alpha, default off). |
| 85 | + |
| 86 | +### Behavior |
| 87 | + |
| 88 | +* If both CPU and memory are controlled, VPA enforces the ratio. |
| 89 | +* Applies to Target, LowerBound, UpperBound, and UncappedTarget. |
| 90 | +* If ratio cannot be applied (e.g., missing CPU), fallback to standard recommendations. |
| 91 | +* With feature gate OFF: recommendations are unaffected. |
| 92 | + |
| 93 | +### Feature Enablement and Rollback |
| 94 | + |
| 95 | +#### How can this feature be enabled / disabled in a live cluster? |
| 96 | + |
| 97 | +* Feature gate name: `MemoryPerCPURatio` |
| 98 | +* Default: Off (Alpha) |
| 99 | +* Components depending on the feature gate: |
| 100 | + * recommender |
| 101 | + |
| 102 | +**When enabled**: |
| 103 | +* VPA honors `memoryPerCPU` in recommendations. |
| 104 | + |
| 105 | +**When disabled**: |
| 106 | +* `memoryPerCPU` is ignored. |
| 107 | +* Recommendations behave as before. |
| 108 | + |
| 109 | +### Kubernetes Version Compatibility |
| 110 | + |
| 111 | +The `memoryPerCPU` feature requires VPA version 1.5.0 or higher. The feature is being introduced as alpha and will follow the standard Kubernetes feature gate graduation process: |
| 112 | +- Alpha: v1.5.0 (default off) |
| 113 | +- Beta: TBD (default on) |
| 114 | +- GA: TBD (default on) |
| 115 | + |
| 116 | +### Validation |
| 117 | + |
| 118 | +* `memoryPerCPU` must be > 0. |
| 119 | +* Value must be a valid `resource.Quantity` (e.g., `512Mi`, `4Gi`). |
| 120 | + |
| 121 | +### Test Plan |
| 122 | + |
| 123 | +* Unit tests ensuring ratio enforcement logic. |
| 124 | + |
| 125 | +## Implementation History |
| 126 | + |
| 127 | +* 2025-08-19: Initial proposal |
| 128 | + |
| 129 | +## Future Work |
| 130 | + |
| 131 | + |
| 132 | +## Alternatives |
| 133 | + |
0 commit comments