Provider Connectors

Kubernetes recommendations

How LevelFour sizes container requests, keeps room for the JVM heap and your namespace limits, works with HPA, KEDA and VPA, changes NodePools, node groups and volume claims, checks every change once it lands, and measures what it saved on your bill.

LevelFour recommends CPU and memory requests for the containers in the namespaces you opted in, Jobs and CronJobs included, and HPA minimums and targets. With agent 0.3.0, it also recommends changes to Karpenter NodePools and managed node groups, and smaller PersistentVolumeClaims. Each recommendation arrives on the Savings page like any other. You approve a container, NodePool or node group change as a pull request on your own repository, and run a claim resize yourself. The optional automation component can merge the safest of these pull requests for you, and fix OOM kills and CPU throttling on running pods.

How a request is sized

A recommendation starts from what the container used over the last 14 days, hour by hour, and adds headroom on top. A RecommendationsConfig object can set a window of 1 to 30 days instead. CPU is sized from its p99, memory from its peak, and neither goes below what the container needs while it starts. Containers built on runtimes that hold memory up front, such as the JVM and .NET, get more headroom than others.

JVM heap

A JVM can grow its heap to its maximum at any time, so its memory request never drops below that maximum plus the memory the JVM uses outside the heap: 256 MiB plus a tenth of the heap. With agent 0.4.1, LevelFour reads the maximum from -Xmx, or from -XX:MaxRAMPercentage times the memory limit, in the container's command or its Java options variables. What the agent reads lists them. A container whose image names a JVM and sets neither flag counts its heap as 25% of its memory limit, the JVM's default.

A JVM with no -Xmx and no memory limit gets no memory cut, because nothing caps its heap. Java options set from a ConfigMap or a Secret stay unread, so that container's heap counts as unknown, and it keeps the extra headroom of its runtime. The workload drawer's Spec section shows each container's heap and the floor it sets.

Namespace limits

With agent 0.4.1, recommendations stay inside each namespace's LimitRange and ResourceQuota, so Kubernetes accepts the new pods:

  • LimitRange. No request or limit goes below the minimum or above the maximum. A cut keeps the container's limits, so the request stays at or above each limit divided by the maximum limit-to-request ratio.
  • ResourceQuota. A raise, such as more memory after OOM kills, fits in what the quota has left. When the quota caps it, the recommendation says so.

The namespace page lists its quotas, with what is used against each hard value, and its LimitRanges.

Jobs and CronJobs

A Job's pods run for minutes and stop, so LevelFour sizes a Job or a CronJob from everything its runs used, start to finish, across the runs it saw. It waits until it has seen runs on enough days, as it waits for any container. The pull request edits the Job's pod template, under spec.jobTemplate for a CronJob.

Sizing policies

A sizing policy sets how much room a namespace or a workload keeps. Set it on the namespace page, or on one workload from its drawer. A workload's policy wins over its namespace's.

PolicyCPUMemoryUse it for
Maximum savingsp95, with the least headroomPeak, with the least headroomBatch jobs and workloads that tolerate a little throttling
Balanced (default)p99, headroom from how spiky usage isPeak, headroom from how spiky usage isMost services
Extra headroomBalanced plus 15 pointsBalanced plus 15 pointsLatency-sensitive services and anything that recently regressed

A change applies from the next scan. A recommendation already published keeps the sizing it had. Admins and members can change a policy; viewers see it.

Set the policy with objects in the cluster

With the automation component installed, you can set the sizing policy in the cluster instead, with a ClusterRecommendationsConfig, NamespaceRecommendationsConfig or WorkloadRecommendationsConfig object. The sizing policy shows one. An object wins over the policy set in LevelFour, and the most specific object wins. The objects shape recommendations whether or not automation is turned on, and they offer four settings the dashboard does not:

  • MaxHeadroom: Balanced plus 30 points, up to 80% headroom, for the services that need the most room.
  • cpuPolicy and memoryPolicy: a policy for each resource on its own.
  • customTimeWindowDays: the days of usage a recommendation reads, from 1 to 30. With automation on, a container takes no step before it has that many days.
  • memoryRequestEqualsLimit: the memory limit moves to the recommended memory request, so the two stay equal, and a JVM's heap floor is measured against that new limit.

A field no object sets keeps the policy set in LevelFour, or its default. A regression still lifts a container to at least Extra headroom for 30 days.

HPA, KEDA and VPA

HPA and KEDA. When an autoscaler scales on CPU or memory utilization, lowering the request would make it scale earlier. LevelFour changes the target with the request, in the same pull request, so the autoscaler keeps firing at the same real usage. When the new target would land outside 1 to 90 percent, LevelFour skips that resource. A target set as an average value is independent of the request, so the request changes alone.

HPA minimum and target. LevelFour also recommends changes to the HPA itself:

  • A lower minReplicas, when the HPA sits at its minimum in at least 90% of the hours and its pods use less than half of the target there. The extra replicas are what you pay for.
  • A higher CPU target, 70%, when the HPA scales on CPU utilization with a target under 50% and its pods are never throttled.

Each one arrives as its own pull request on the HPA.

VPA. A VPA in Auto, Recreate, Initial or InPlaceOrRecreate mode writes the requests it controls, so LevelFour leaves those alone. Its container policy decides which: a container set to mode: Off, or a resource left out of controlledResources, still gets a recommendation. A VPA in Off mode only recommends, so the workload gets a recommendation, with the VPA's own target shown beside it.

NodePools, node groups and claims

These need agent 0.3.0 in the cluster. A NodePool or node group change covers every workload on the pool, so it does not wait for namespace opt-in. Node optimization explains how LevelFour picks each change and prices it.

RecommendationWhat it changesHow you apply it
NodePoolThe NodePool's requirements and spec.disruption settingsMerge the pull request on the source that deploys the NodePool: an Argo CD application, a Helm release or a manifest in your repository
Node groupinstance_types and capacity_type of a managed node groupMerge the pull request on the Terraform that defines the group
Claim resizeA PersistentVolumeClaim's sizeManual Setup: create a smaller claim and copy the data across, following the steps in the recommendation. PersistentVolumeClaim resize explains why it takes a new claim

After you merge

LevelFour watches every merged change in your cluster. For a container:

  1. Rolled out. The cluster runs the new requests.
  2. Verified or Regressed. A day later, LevelFour compares OOM kills, restarts and CPU throttling against the week before. More of any of them is a regression.
  3. Reverted. After a regression, LevelFour opens a pull request that puts the old values back. Once the cluster runs them, the next recommendation for that container uses Extra headroom for 30 days, whatever its policy.

LevelFour marks a change as never applied when its pull request closes unmerged, or when nothing rolls it out within 30 days.

A change that regressed, was reverted or never applied keeps its logs on the saving and offers no Retry. The next change for that container arrives as a new recommendation.

The workload drawer shows each step on its timeline, next to the pull request that opened and merged it.

For the other kinds, LevelFour reads what the cluster runs:

  • NodePool: rolled out once the NodePool in the cluster carries the recommended fields.
  • Node group: rolled out once every node in the group runs a recommended instance type on the recommended capacity type.
  • Claim resize: verified once the workload mounts a new claim, created after the recommendation, at or under the new size. A resize has nothing left to regress, so it skips the day-later check.

A day after a NodePool or node group change rolls out, LevelFour checks the workloads with pods on the pool against the week before. Evictions at a higher rate, or pods waiting to be scheduled for at least 10 minutes in total at more than twice the rate, mark it Regressed. It reads Reverted once the pool's old settings are back in the cluster.

Realized savings

A week after a verified rollout, LevelFour compares what the container cost the week before and the week after, from your bill, and records the difference as realized savings on Savings Audit. A scale-to-zero or a deleted volume saves what it cost before. For a NodePool or node group, LevelFour compares the cost of the pool's nodes, and for a claim resize, the cost of its volume.

A lower request cuts the container's share of the bill at once. Your node bill drops when nodes consolidate and fewer of them run, so it can trail the realized figure by a few days.

Signals on the Kubernetes pages

Suspected memory leak. Memory climbs in a steady line between restarts, by at least 20 percent over at least a day. LevelFour holds back any memory cut for that container, because its peak only says how far it got before it restarted.

CPU runaway. CPU climbs in a steady line with no restart, by at least 50 percent over at least a day.

GPU. When Prometheus scrapes NVIDIA's DCGM exporter, each container shows GPU utilization and GPU memory used against what its GPUs hold. Configuration has the setup.

Health score. The fleet table scores each cluster from 0 to 100. Efficiency, the share of container cost not wasted, counts 40 percent. Reliability, the share of workloads not at risk with a medium risk counting half a high one, counts 40 percent. Hygiene, the share of containers with CPU and memory requests and a memory limit, counts 20 percent. Hover the score to see each part.

CO2 estimate. The fleet table and the cluster page estimate each cluster's operational emissions over the date range, with Cloud Carbon Footprint's method and its published coefficients: compute energy from each node's vCPU hours at the CPU use the agent measured (50 percent where none was), plus memory energy, times the cloud's power usage effectiveness and the region's grid emission factor. A node type whose CPU LevelFour cannot place uses its cloud's average for that CPU. The estimate leaves out the emissions of building the hardware. A cluster with no cloud, or in a region with no published grid factor, gets no estimate.

Compare two periods. Turn on Compare next to the date range on a cluster page to see cost, efficiency and waste for two periods side by side.

Group by a virtual tag. The cost views group by any virtual tag that has Kubernetes rules. A tag whose rules pick clusters and namespaces works as an allocation group: one value can sum namespaces from several clusters.

Save a report. Save report on a Kubernetes cost view keeps its grouping, metric and cluster. Open it again from Reports and read it by day, by week (Monday to Sunday) or by month. A period the date range cuts is marked partial.

Alerts and the weekly summary

Cost alerts can watch a cluster, a namespace or a workload: its cost or its waste against a budget, or its reliability at a minimum risk, posting in your Slack channels. A reliability alert can send each namespace to its own channels, as Kubernetes alerts explains, and any alert can also reach Datadog as an event. Switch on the Kubernetes group in notification preferences to get a summary every Monday with each cluster's cost and unused spend, per namespace. It starts off.

On this page

Ask the FinOps Agent about your cloud spend