Beware of Kubernetes autoscaling if you want reliable, cost-efficient services

by Stefano Doni

February 17, 2022

Share this post

Beware of Kubernetes autoscaling if you want reliable, cost-efficient services

Autoscaling is sold as the button that keeps Kubernetes efficient on its own. Be careful before you trust it.

Kubernetes autoscalers scale on resource usage alone. They do not look at application signals such as response time. So a change that looks efficient on a CPU chart can quietly break your latency SLO and, at the same time, raise your cloud bill. In one real case, a Java microservice on Azure, tuning the Kubernetes requests, limits and JVM settings together cut cloud cost by 49% while keeping response time inside its SLO. This article shows how that happens and what to do about it.

Many teams running on the cloud pay far more than they expected. Over-provisioning is the usual culprit: it is the safe reflex when release cycles are short and there is no time for proper sizing. Moving from on-premise to cloud makes it easy to ignore, because a bigger bill looks like an acceptable price for agility. Sooner or later, though, those bills start to limit how cost-effectively you can deliver services.

Kubernetes resource management adds to the difficulty. Tuning a single microservice by hand often takes weeks, even for experienced SREs and performance engineers. This was exactly the situation at a European leader in SaaS accounting, payroll and business-management services. Their teams were shipping frequent updates for new features and regulations, and cost efficiency had slipped down the priority list.

We use that real case below to show the challenges of tuning Kubernetes Java microservices, especially when autoscaling policies are in place. The same effects apply to any language runtime. We then show how AI-powered optimization finds the best tradeoff between performance, resilience and cost automatically.

Kubernetes autoscaling: a word of caution

Sizing containers and properly setting resource requests and resource limits is very important to ensure performance and resilience (here is why). Kubernetes offers built-in autoscaling to automate this. The Vertical Pod Autoscaler (VPA), for example, recommends CPU and memory requests from measured pod usage.

Here is the catch. Kubernetes autoscalers, VPA included, act on resource usage only. They do not consider application-level metrics such as response time. That gap can hit the performance and resilience of your workloads hard.

Vertical Pod Autoscaler cutting CPU requests until service latency breaches its SLO
Figure 1: Vertical Pod Autoscaling in action

The chart above shows a microservice serving a typical diurnal traffic pattern: low load, then high load, then low again. The top-left panel plots latency against the defined SLO. The lower panels show resource requests and the matching utilization for CPU and memory.

The service first ran under default requests. Then VPA was switched on. VPA saw CPU utilization below 50%, judged the service over-provisioned, and cut CPU requests in half. Under the new settings, latency spiked and the service breached its response-time SLO.

The lesson is direct. You have to evaluate the effect of any recommended setting on the service itself, because a change that looks efficient can degrade performance or reliability. This is what makes tuning Kubernetes microservices hard: requests, limits, autoscaling thresholds and runtime flags all interact, and they have to balance performance, resilience and cost against real SLOs.

A real-world case: a Java microservice on Azure

The customer’s first target was a Java microservice on Azure that provides the B2B authorization service behind all their digital products.

Java B2B authorization microservice running on Azure Kubernetes, the optimization target
Figure 2: Case studied

The baseline configuration for the pod is shown below.

Baseline Kubernetes pod and JVM settings: CPU and memory requests, limits and max heap
Figure 3: Pod initial configuration (baseline)

Both CPU and memory requests were set lower than the limits: 1.5 CPUs and 3.42 GB requested, against limits of 2 CPUs and 4.39 GB. Setting requests below limits is a common way to guarantee enough resources while leaving headroom for growth. At the runtime level, the JVM max heap was set higher than the memory request, so the JVM could use more memory than the pod asked for.

The environment used KEDA autoscaling, with policies on both CPU and memory. The triggers were 70% CPU utilization and 90% memory utilization, measured against requests, not limits. So once CPU usage reaches 1 core (70% of 1.5 cores), KEDA adds a replica.

We ran a load test reproducing the diurnal pattern with this baseline.

Baseline configuration under load: response time spikes from CPU throttling during JVM startup
Figure 4: Behavior of the baseline configuration under load

Two problems showed up. Response time spiked because of high CPU usage and CPU throttling during JVM startup. That hurts performance and reliability at exactly the wrong moment.

The second problem is more subtle. When load dropped, the replica count did not scale back down. Container memory usage stayed above the 90% threshold, so KEDA kept the extra replicas running. The cause here was the JVM max heap sitting above the memory request. In other cases the same effect can come simply from a new release changing the application’s memory footprint.

This is the heart of the matter. Tuning Kubernetes applications for both reliability and cost efficiency is hard, because container requests and limits, autoscaling metrics and thresholds, and runtime flags interact in non-obvious ways. Get one of them wrong and you can pay for replicas you do not need while still missing your SLO.

AI-powered optimization to minimize cost

The first step in the AI-powered optimization process is to state the goal. Here the goal was to minimize the total cost of the service on Azure, which in Kubernetes depends on the allocated CPU and memory. We then set constraints to rule out any configuration that violated the SLOs: throughput, response time and error rate could not degrade by more than 10% against the baseline.

Akamas optimization goal to minimize cloud cost under response-time and error-rate SLO constraints
Figure 5: Optimization goal and constraints

The study tuned nine parameters at once:

  • Four Kubernetes parameters: CPU and memory requests and limits, which drive performance, reliability and cost.
  • Five JVM parameters: including heap size and garbage collector type, which govern the behaviour of containerized Java.

Tuning all nine together keeps the JVM aligned with the chosen container sizing. That is the difference from the manual approach, which tunes each layer on its own and misses the interactions.

Akamas found the best cost configuration after a few dozen experiments, in about 19 hours. Against the baseline, it delivered a 49% improvement on cost and behaved better under load.

Best configuration holds response time within SLO with no autoscaling triggered, versus the baseline
Figure 6: Behavior of best vs baseline configuration

Two differences stand out:

  • Response time in the best configuration stays within the SLO throughout, with no peaks.
  • Autoscaling never triggers, because a fixed replica count sustains the full load.

So the best configuration improves cost and improves performance and resilience at the same time.

Here is the side-by-side comparison.

Side-by-side Kubernetes and JVM parameters for the best cost configuration versus the baseline
Figure 7: Best vs baseline configurations
ParameterBaselineBest (lowest-cost) configuration
CPU requests / limits1.5 / 2 CPUsHigher than baseline
Memory requests3.42 GB5 GB
Memory limits4.39 GBHigher than baseline
JVM max heapAbove memory request+20%, kept within memory request
JVM min heapBelow max heapAlmost equal to max heap
Autoscaling under loadTriggered, no scale-backNot triggered
Cost vs baselineReference49% lower

Two points are worth calling out. The best configuration sets memory and CPU requests and limits higher than the baseline, which feels counterintuitive, since Kubernetes is often seen as best for small, highly scalable pods. And the max heap, though raised by 20%, now sits within the container memory request, while min heap is almost equal to max heap. Keeping min and max heap close helps avoid garbage collection cycles during JVM startup.

The pod is larger in both CPU and memory, so autoscalers fire less often, even though the fixed cost per pod is higher. The apparent paradox resolves once container and runtime parameters are aligned: with the JVM max heap below the memory request, the application scales down cleanly.

The high-resilience alternative

Alongside the lowest-cost result, Akamas surfaced other configurations. After about a dozen experiments (roughly 8 hours), one stood out: it reduced cost by 16% but behaved far better on resilience.

High-resilience configuration: lower response-time peak on scale-out and replicas scaling back after peak load
Figure 8: Behavior of best vs baseline configuration

The response-time peak on scale-out was less than half the baseline.

Replicas scaled back down after the high-load phase.

In this configuration, CPU requests are smaller than the baseline while limits are higher, and memory requests are higher than in the lowest-cost configuration. Several JVM options change too, including the garbage collector set to Parallel, which is more efficient on CPU and memory for this workload.

This higher-resilience result appeared while searching for cost reduction. Stating resilience as the explicit goal, and relaxing other constraints, would likely find an even better one. That was not this customer’s objective, but it shows the value of exploring tradeoffs automatically instead of guessing.

Conclusions

Tuning Kubernetes applications with dozens of microservices by hand is no longer feasible. It means juggling hundreds of parameters across several technology layers at once, and it gets harder when utilization-based autoscaling is in the mix.

Akamas AI takes all of these factors into account automatically. It identifies the best configuration without manual effort and without prior knowledge of the application, the Kubernetes setup or the autoscaling policies.

With Akamas, architects, performance engineers and SREs declare a goal (minimize cloud cost, or maximize resilience) and constraints (a response-time SLO), and get configurations plus a clear view of the tradeoffs. The result is real cost savings, better performance and resilience, and less manual toil across every team involved in delivering the service.

Want to see this on your own workloads? Explore Akamas for Kubernetes workloads and JVM-on-Kubernetes optimization.

FAQs

What is Kubernetes autoscaling?

Kubernetes autoscaling adjusts resources automatically to match load. The Horizontal Pod Autoscaler changes the number of replicas. The Vertical Pod Autoscaler changes per-pod CPU and memory requests. The Cluster Autoscaler adds or removes nodes. KEDA scales on external and resource metrics.

Why can Kubernetes autoscaling hurt reliability?

Autoscalers act on resource usage, not on application metrics such as response time. A change that looks efficient on CPU can push latency past its SLO. Always validate a scaling decision against the service’s own performance, not just utilization.

Does autoscaling always reduce cost?

No. Misaligned container and runtime settings can keep replicas running when load drops. In the case above, a JVM heap set above the memory request held memory utilization high, so replicas never scaled back and cost stayed up.

HPA vs VPA: what is the difference?

The Horizontal Pod Autoscaler scales out by adding replicas. The Vertical Pod Autoscaler resizes a pod by changing its CPU and memory requests. They solve different problems and can conflict if used together without care.

How do you autoscale Kubernetes without breaking SLOs?

Tune container requests and limits, runtime settings and scaling thresholds together, against an explicit SLO constraint rather than one layer at a time. Akamas does this automatically: in the case above it cut cost 49% while holding the response-time SLO.

Akamas named a Leader in the GigaOm Radar for Cloud Resource Optimization v5, 2026
Akamas named an Outperformer in the GigaOm Radar for Cloud Resource Optimization v5, 2026

See for Yourself

Experience the benefits of Akamas autonomous optimization.
No overselling, no strings attached, no commitments.